c语言数据类型长度
头文件<limits.h>和<float.h>中说明了基础数据的长度。float,double和long double的范围就是在IEEE 754标准中提及的典型数据。
关键字 | 位长(字节) | 范围 | 格式化字符串 |
---|---|---|---|
char |
1 | -128..127(或0..255,与体系结构相关) | %c |
unsigned char |
1 | 0..255 | |
signed char |
1 | -128..127 | |
int |
2(16位系统) 或 4 |
-32768..32767 或 -2147483648..2147483647 |
%i, %d |
unsigned int |
2 或 4 |
0..65535 或 0..4294967295 |
%u |
signed int |
2 或 4 |
-32768..32767 或 -2147483648..2147483647 |
%i, %d |
short int |
2 | -32768..32767 | %hi |
unsigned short |
2 | 0..65535 | %hu |
signed short |
2 | -32768..32767 | |
long int |
4 或 8[3] |
-2147483648..2147483647 或 -9223372036854775808..9223372036854775807 |
%li, %ld |
unsigned long |
4 或 8 |
0..4294967295 或 0..18446744073709551615 |
%lu |
signed long |
4 或 8 |
-2147483648..2147483647 或 -9223372036854775808..9223372036854775807 |
|
long long |
8 | -9223372036854775808..9223372036854775807 | %lli |
unsigned long long |
8 | 0..18446744073709551615 | %llu |
float |
4 | 3.4x10-38..3.4x10+38 (7 sf) | %f, %e, %g |
double |
8 | 1.7x10-308..1.7x10+308 (15 sf) | %f, %e, %g |
long double |
8 或以上 | 编译器相关 | %Lf, %Le, %Lg |