#include <stdio.h>
int main() {
printf("the size of 'char': %d Byte\n", sizeof(char));
printf("the size of 'short int': %d Byte\n", sizeof(short int));
printf("the size of 'int': %d Byte\n", sizeof(int));
printf("the size of 'unsigned int': %d Byte\n", sizeof(unsigned int));
printf("the size of 'float': %d Byte\n", sizeof(float));
printf("the size of 'double': %d Byte\n", sizeof(double));
printf("the size of 'long': %d Byte\n", sizeof(long));
printf("the size of 'long long': %d Byte\n", sizeof(long long));
printf("the size of 'unsigned long': %d Byte\n", sizeof(unsigned long));
printf("the size of 'void*': %d Byte\n", sizeof(void*));
return 0;
}
在64位Linux(Debian)系统下编译此程序:
-
编译为64位程序
gcc type_szie.c -o type_size_64.out
结果如下所示: -
编译为32位程序
- 安装编译32位程序所需的软件包
sudo apt install build-essential module-assistant gcc-multilib g++-multilib
- 编译
gcc -m32 type_szie.c -o type_size_32.out
结果如下所示:
- 分析
32位的寻址空间是\(2^{32}\), 即32个bit, 也就是4个字节. 同理64位编译器.
参考博客:
- https://www.cnblogs.com/l199616j/p/10401094.html
- https://blog.csdn.net/longintchar/article/details/50557832