#include <stdio.h>
union p
{
int x;
char y;
}
k = {.y = 97};
int main()
{
printf("%d\n", k.y);
return 0;
}
OUTPUT: 97
I came across this Question. As we know we can only initialize the first member of Union. But in this, at the time of initialization, the y
variable is initialized through some given method!
Can anyone explain this to me how k={ .Y=97} is breaking the rule stated in Dennis Ritchie's book "Union can only be initialized with a value of the type of its first member" and initializing the second variable instead ?