长整型整数的大小和C中的整型显示4个字节

人气:856 发布:2022-10-16 标签: int c size declaration long-integer

问题描述

我做了以下实验,以了解长整型和整型在我的系统中的大小

系统规范: 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/

(前缀singnedunsigned对所需空间没有影响)

如果要使用指定的位宽,我建议使用int32_tuint64_t

650