Can anyone explain this C program..
Hi,
I was just trying something with C and I stumbled upon this little piece of code.
void main()
{
union
{
int a;
struct
{
char b;
char c;
}ch;
}num;
num.a=0;
num.ch.c++;
printf("%d",num.a);
}
The answer came out to be 256.
Each time I increment num.ch.c, the value of num.a increases by 256.
ie, if the value of num.ch.c is 3, the value of num.a would be 762.
Why is this so?
Note that, if I change the value of num.a, the value of num.ch.c does not change. It remains the same as num.a, which should be expected.
Please explain..