What is the output of following program?
main ( )
{
union a
{
int i;
char ch[z];
}
union a,u;
u∙i=256
printf (%d%d%d,u∙i,u∙ch[0],u∙ch[1] );
}
- 255 1 0
- 256 0 1
Explanation:
In union all elements refer to the same slot of memory. Thus in ▁(union a) if 2 bytes say 4501 & 4502 are allocated to ▁(int i) then ch[0] refers to 4501 & ch[1], to 4502.
- 256 1 0
- 255 0 1
How are they deciding u.ch[0] = 0 or u.ch[1] =1 ????