I have executed the following program
The output was - 100 200 300.Code:#include <stdio.h> struct test { int a,b,c; }test; struct test testObj; main() { testObj.a = 100; testObj.b = 200; testObj.c = 300; printf("%d %d %d \n", testObj, testObj, testObj); return 0; }
I was expecting ouput as - 100 100 100.
Can anyone explain why the output is like this?
I tried looking into the assembly code for the same program and I found that before a call to printf the elements are pushed into the stack as following
testobj+8
testobj+4
testobj
When I replaced the printf statement with the following one
still I got the same o/p (even the assembly was also the same).Code:printf("%d %d %d \n", testObj, testObj, testObj.b);
Is it related to the compiler?
Pointers please.....
Gvs



LinkBack URL
About LinkBacks


