#include <stdio.h>
int main()
{
union a
{
int i;
char ch[2];
};
union a u;
u.ch[0] = 0;
u.ch[1] = 2;
u.ch[2] = 0;
u.ch[3] = 0;
printf("%d\n",u.i);
return 0;
}
In this program, if the size of integer is given to be 4 bytes, then how is it that the output will be 512? We will see that out of the 4 bytes, the first two bytes will be occupied by 0
and 0
. Then why am I getting that as the output?