Can you explain the results from printing members of a union?
Could anyone tell me why data.i and data.f were corrupted? The website from which this code is from tries to explain it but uses bad grammar and many typos so I was wondering if anyone here might assist me.
#include
#include
union Data
{
int i;
float f;
char str[20];
};
int main( )
{
union Data data;
data.i = 10;
data.f = 220.5;
strcpy( data.str, "C Programming");
printf( "data.i : %d\n", data.i);
printf( "data.f : %f\n", data.f);
printf( "data.str : %s\n", data.str);
return 0;
}
When the above code is compiled and executed, it produces following result:
data.i : 1917853763
data.f : 4122360580327794860452759994368.000000
data.str : C Programming