In the below code, if I print the values of union members the unassigned member int i;
outputs 515
. I found out that it gives the positional weight of the whole union.
Q :-But if that is declared as float i;
it outputs 0.000
. Any particular reason for this behaviour. How this works?
#include<stdio.h>
int main()
{
union a
{
float i;
char ch[2];
};
union a u;
u.ch[0] = 3;
u.ch[1] = 2;
printf("%d, %d, %f\n", u.ch[0], u.ch[1], u.i);
return 0;
}