I have following program.
int main () {
int a = 1;
long long b = 100000000;
printf("size of a is: %d \t sizeof b is:%d \n",sizeof(a),sizeof(b));
printf("a= %d b=%d a=%d \n", a, b, a);
printf("a= %d b=%Ld a=%d \n", a, b, a);
b = 10000000000;
printf("a= %d b=%d a=%d \n", a, b, a);
printf("a= %d b=%Ld a=%d \n", a, b, a);
}
When I compile it with gcc -m32
output is
size of a is: 4 sizeof b is:8
a= 1 b=100000000 a=0
a= 1 b=100000000 a=1
a= 1 b=1410065408 a=2
a= 1 b=10000000000 a=1
but when it is compiled with gcc -m64
output is.
size of a is: 4 sizeof b is:8
a= 1 b=100000000 a=1
a= 1 b=100000000 a=1
a= 1 b=1410065408 a=1
a= 1 b=10000000000 a=1
Why does it show wrong values while printing third printf argument (a)?
My gcc version is
priyanka@priyanka-N551JB:~$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu