java,c,c++ 语言之间基本数据类型的比较

论坛 期权论坛     
匿名小用户   2019-10-20 18:13   94   0
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
转载自<a data-token="72849864335b2702da42d001698ea5d9" href="http://blog.csdn.net/wu928320442/article/details/5825170" rel="nofollow">http://blog.csdn.net/wu928320442/article/details/5825170</a></p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
当要进行底层移植的时候肯定会遇到这些问题。特整理了下。</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
<span style="font-size:14px;"><strong><span style="font-size:12px;"><span style="font-weight:normal;"><br></span></span></strong></span></p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
</p>
<h1 class="title_txt" style="color:rgb(51,51,51);font-family:Arial;line-height:26px;">
<a name="t0" style="color:rgb(51,102,153);"></a>java语言基本数据类型</h1>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
在JAVA中一共有八种基本数据类型,他们分别是</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
byte、short、int、long、float、double、char、boolean</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
整型</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
其中byte、short、int、long都是表示整数的,只不过他们的取值范围不一样</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
byte的取值范围为-128~127,占用1个字节(-2的7次方到2的7次方-1)</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
short的取值范围为-32768~32767,占用2个字节(-2的15次方到2的15次方-1)</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
int的取值范围为(-2147483648~2147483647),占用4个字节(-2的31次方到2的31次方-1)</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
long的取值范围为(-9223372036854774808~9223372036854774807),占用8个字节(-2的63次方到2的63次方-1)</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
可以看到byte和short的取值范围比较小,而long的取值范围太大,占用的空间多,基本上int可以满足我们的日常的计算了,而且int也是使用的最多的整型类型了。</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
在通常情况下,如果JAVA中出现了一个整数数字比如35,那么这个数字就是int型的,如果我们希望它是byte型的,可以在数据后加上大写的B:35B,表示它是byte型的,同样的35S表示short型,35L表示long型的,表示int我们可以什么都不用加,但是如果要表示long型的,就一定要在数据后面加“L”。</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
浮点型</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
float和double是表示浮点型的数据类型,他们之间的区别在于他们的精确度不同</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
float 3.402823e+38 ~ 1.401298e-45(e+38表示是乘以10的38次方,同样,e-45表示乘以10的负45次方)占用4个字节</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
double 1.797693e+308~ 4.9000000e-324 占用8个字节</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
double型比float型存储范围更大,精度更高,所以通常的浮点型的数据在不声明的情况下都是double型的,如果要表示一个数据是float型的,可以在数据后面加上“F”。</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
浮点型的数据是不能完全精确的,所以有的时候在计算的时候可能会在小数点最后几位出现浮动,这是正常的。</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
boolean型(布尔型)</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
这个类型只有两个值,true和false(真和非真)</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
boolean t = true;</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
boolean f = false;</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
char型(文本型)</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
用于存放字符的数据类型,占用2个字节,采用unicode编码,它的前128字节编码与ASCII兼容</p>
<p style="color:rgb(51,51,51);font-family:Arial;font-size:14px;line-height:26px;">
字符的存储范围在/u0000~/uFFFF,在定义字符型的数据时候要注意加' ',比如 '1'表示字符'
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:50
帖子:1079
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP