C语言中 int long float double分别占用了多少个字节??

如题所述

char/signed
char/unsigned
char:
1个字节;
char*(即指针变量):
2个字节(16位编译器)
4个字节(32位编译器)
8个字节(64位编译器)
short
int:
2个字节
int/unsigned
int:
2个字节(16位编译器)
4个字节(32/64位编译器)
long
int:
4个字节
float:
4个字节
double:
8个字节
long
double:
8/10/12/16?
long/unsigned
long:
4个字节(16/32位编译器)
8个字节(64位编译器)
long
long:
8个字节
string:
字符个数+1
上面的只是参考,具体的长度你可以在你的编译器中使用sizeof关键字分别求出来。
温馨提示:内容为网友见解,仅供参考
第1个回答  2019-03-18
各数据类型所占字符数如下:
int

4字节
float

4字节
double

8字节
long

4字节
unsigned
long

4字节
可以通过如下的语句进行验证。
printf("%d\n", sizeof(int)); // 计算int型所占字节数
printf("%d\n", sizeof(float)); // 计算float型所占字节数
printf("%d\n", sizeof(double)); // 计算double型所占字节数
printf("%d\n", sizeof(long)); // 计算long型所占字节数
printf("%d\n", sizeof(unsigned long)); // 计算unsigned long型所占字节数
相似回答