static int i = 2;
union U {
int a, b;
char c[3];
}u;
int main(){
u.b = 0x6;
for(;i; u.b++)
u.b = u.a << i--;
printf("%d %o %s", u.a, u.b, u.c);
return 0;
}
This code gives the output for the character array as 3. Now I know that this code poses several Undefined Behaviour
specially when I am a storing into one variable and accessing of some other, but just for the purpose of experiment, can anybody explain to me why u.c
has a value of 3
.
Note: Internal memory structure would be better to understand this