I stumbled across a code based on unions in C. Here is the code:
union {
struct {
char ax[2];
char ab[2];
} s;
struct {
int a;
int b;
} st;
} u ={12, 1};
printf("%d %d", u.st.a, u.st.b);
I just couldn't understand how come the output was 268 0
. How were the values initialized?
How is the union functioning here? Shouldn't the output be 12 1
. It would be great if anyone could explain what exactly is happening here in detail.
I am using a 32 bit processor and on Windows 7.