and the o/p isCode:union a
{
int a;
char ch[2];
};
int main()
{
union a u;
u.ch[0]=3;
u.ch[1]=2;
printf("%d %d %d", u.ch[0],u.ch[1].u.a);
}
3 2 515
some body plz exlain how...
Printable View
and the o/p isCode:union a
{
int a;
char ch[2];
};
int main()
{
union a u;
u.ch[0]=3;
u.ch[1]=2;
printf("%d %d %d", u.ch[0],u.ch[1].u.a);
}
3 2 515
some body plz exlain how...
I think your output will be different each time unless you happen to have
char - 1 byte
int - 2 bytes
Indeed... I get the same result if I make it a short.
Anyway, it's setting the individual bytes of the int so to speak.
Byte 1 = 3
Byte 2 = 2
On high endian machines, that would make the short equal to 0x0203.
Input that into a calculator and convert to decimal and you get 515.