这里(64位操作系统)我通过程序来证明C语言中int,char这样的数据类型的大小。sizeof()用来计算变量的字节大小。
#include <stdio.h>
int main()
{
printf("%d\n",sizeof(char));
printf("%d\n",sizeof(short));
printf("%d\n",sizeof(int));
printf("%d\n",sizeof(long));
printf("%d\n",sizeof(long long));
printf("%d\n",sizeof(float));
printf("%d\n",sizeof(double));
printf("%d\n",sizeof(long double));
return 0;
}
结果如下:
对于不同位数的操作系统,有些数据类型所占的字节数也不一样,这里列几个常用的:
Data | 16bit | 32bit | 64bit |
---|---|---|---|
char | 1 byte | 1 byte | 1 byte |
int | 2 bytes | 4 bytes | 4 bytes |
float | 4 bytes | 4 bytes | 4 bytes |
double | 8 bytes | 8 bytes | 8 bytes |
long | 4 bytes | 4 bytes | 8 bytes |