long int的大小差异

pra*_*km -2 c

我在使用long intC 时遇到尺寸不适.以下代码:

#include <stdio.h>

void main()
{
    printf("%d\n", sizeof(long int));
}
Run Code Online (Sandbox Code Playgroud)

给出8作为输出,所以64位用于表示long int,对吗?但:

#include <stdio.h>

void main()
{
    long int a;
    a = 1;
    a = a << 32;
    printf("%d\n", a);
}
Run Code Online (Sandbox Code Playgroud)

给出0(移位31给出-2147483648,即-2**31).因此,似乎只使用了4个字节.这是什么意思?我正在使用没有标志的gcc 4.4.5

Yuu*_*shi 9

你将它打印为普通整数:printf("%d").尝试将其打印为长整数:printf("%ld ...").