问题描述
我做了以下实验,以了解长整型和整型在我的系统中的大小
系统规范: 64位Windows 7 GCC MinGW编译器 Eclipse CDT我把我得到的结果搞糊涂了。我没有理由支持我的计划的结果,如果有人对此有任何想法,请分享并帮助我。
程序:
#include<stdio.h>
#include<conio.h>
int main(){
unsigned long int b;
unsigned int a;
printf("%d",sizeof(b));
printf("
");
printf("%d",sizeof(a));
}
输出:
4
4
同一程序的在线GCC编译器4.8.1版输出不同
8
4
推荐答案
规格说明
sizeof(int) <= sizeof(long)
,但long
至少为32位,int
为16位。
http://www.cplusplus.com/doc/tutorial/variables/
(前缀singned
或unsigned
对所需空间没有影响)
如果要使用指定的位宽,我建议使用int32_t
、uint64_t
等