size_t i = 0;
union a u;
for (i = 0; i < sizeof(int); ++i)
if (i == 0)
u.ch[i] = 1;
u.ch[i] = 0;
printf("%d %d %d\n",u.ch,u.ch,u.i);
I understand. The byte 3 and byte 4 are not zeros as I assumed, they must be garbage. I assumed they would be all zeros because of the rule "if you initialize one member of a structure, others are initialized to 0 automatically". I thought this applied to unions also.