C/C++基本数据类型

1、基本数据类型
布尔型:bool
字符型:char
整形 :short int long
浮点型:float double

2、数据范围

bool   flase~true(1 Byte)
char   -128 ~ +127 (1 Byte)
short  -32767 ~ + 32768 (2 Bytes)
int    -2147483648 ~ +2147483647 (4 Bytes)
long   -2147483648 ~ +2147483647 (4 Bytes)
float  -3.4*10(-38)~3.4*10(38) (4 Bytes) 
double -1.7*10(-308)~1.7*10(308)(8 Bytes) 

(1)bool只有true和false两个值,一般认为是1Byte,但据说以编译器实现为准。
(2)char主要用于表示字符,具体可查看ASCII码表(百度百科链接)
(3)short/int/long三种整形,可以看到int和long数据范围一致,但是仅针对目前的32位操作系统。标准没有严格规定short/int/long所占用的字节数,只做了宽泛的限制:short <= int <= long。其他不同位数不同操作系统可能有不同定义,所以使用时需要考虑实际的情况。
(4)float-单精度,提供7位有效数字位;double-双精度,提供15~16位有效数字。

3、关于signed/unsinged
signed(有符号)/unsinged(无符号),即是否有正负值。
char/signed char/unsinged char,一般认为char和signed char一致,但是据说有些编译器char取值范围和signed char不同。不过一般使用的都是char,不会刻意区分signed/unsinged。
short/int/long默认为signed,用unsinged修饰后数值范围有所改变,把负数部分的取值加到正数上。
float/double一般不用signed/unsinged修饰,因为和整形的计算方式不同,不是单纯的数字。

4、long long/__int64类型
一般认为long long占8Bytes,同样没有严格定义(short <= int <= long<=long long)。
__int64/__int32/__int16/__int8,这些是微软定义的类型,即占64位/32位/16位/8位。

猜你喜欢

转载自blog.csdn.net/wizardtoh/article/details/53836493