基本数据类型范围

  类型 取值范围 大致范围 字节 其他
整型 int 

   -2147483648 ~ +2147483647  

(-2^31~+(2^31-1))

-2×10^9~2×10^9 4 Bytes  
long long   -2^63~+(2^63-1) -9×10^18~9×10^18 8 Bytes  

浮点型

浮点数值=尾数×底数 ^ 指数

float

-2^128~+2^128

实际精度6~7位 4 Bytes

1bit(符号位)+8bits(指数位)+23bits(尾数位)

精度是由尾数的位数来决定的2^23=8388608(7位)

double 

-2^1024~+2^1024

实际精度15~16位 8 Bytes

1bit(符号位)+11bits(指数位)

+52bits(尾数位)

2^52 = 4503599627370496(16位)

字符型 char -128~+127 -128~+127 1 Byte  
布尔型 bool 0 or 1 0 or 1 1 Byte  

1.long long int 型赋大于2^31-1的初值,需要在初值后面加上LL,否则会编译错误。

2.对于整型数据,都可以在前面加个 unsigned,以表示无符号型,例如unsigned  int 和unsigned long long,占用的位数和原先相同,但是把负数范围挪到正数上来了。 也就是说,unsigned int 的取值范围是0~2^32 - 1, unsigned long long的取值范围是0~2^64 -1。

3. #define pi 3.14    const double pi=3.14;

4.i++是先使用i再将i加1,++i是先将i加1再使用i 

5. typedef long long LL; 给复杂的数据类型起别名。

猜你喜欢

转载自blog.csdn.net/m0_37345402/article/details/81603839