Hi,
I have below piece of code :
Code:
#include <stdio.h>
void main()
{
union a
{
int i;
char ch[2];
};
union a key;
key.i=512;
printf("\n key.i= %d",key.i);
printf("\n key.ch[0]= %d",key.ch[0]);
printf("\n key.ch[1]= %d",key.ch[1]);
key.ch[0]=50;
printf("\n key.i= %d",key.i);
printf("\n key.ch[0]= %d",key.ch[0]);
printf("\n key.ch[1]= %d",key.ch[1]);
}
Results:
-----------
For the first set when key.i is 512,
key.ch[0]=0 and key.ch[1]=2 and key.i=512
However for second set of data ie when ch[0]=50 its showing as
key.i=562
key.ch[0]=50 and key.ch[1]=2
Can anyone please explain me how key.i is 562? This stuff is something to do with endianness.