I’m getting a size discepancy while using long int in C. The following code:
#include <stdio.h>
void main()
{
printf("%d\n", sizeof(long int));
}
gives 8 as output, so 64 bits are used to represent long int, right? But:
#include <stdio.h>
void main()
{
long int a;
a = 1;
a = a << 32;
printf("%d\n", a);
}
gives 0 (shifting by 31 gives -2147483648, which is -2**31). So, it seems that only 4 bytes are being used. What does this mean? I’m using gcc 4.4.5 with no flags
You’re printing it as a normal integer:
printf("%d"). Try printing it as a long integer:printf("%ld ...").