Saturday, 15 January 2011

c - Why is the output 0 2 all the time when it should be garbage? -



c - Why is the output 0 2 all the time when it should be garbage? -

this question has reply here:

a question union in c 6 answers #include<stdio.h> int main() { union { int i; char ch[2]; }; union z = {512}; printf("%d %d",z.ch[0],z.ch[1]); homecoming 0; }

the output is: 0 2 why output 0 2, when should garbage value?

i not sure why expect compiler generate garbage you, when have told initialize i 512. to the lowest degree 2 important bytes of 512 0 , 2.

implementation-specific behavior not same garbage.

c unions

No comments:

Post a Comment