#include <stdio.h>
union p{
int x;
float y;
};
int main()
{
union p p;
p.x = 10;
printf("%f\n", p.y);
return 0;
}
Conclusion:
0.000000
When I try to compile the above program, it does not show any warnings, even in the main function. Why printfdoesn't it print the value 10.00000?
I read some related questions about stackoverflow, which explains the behavior printfwhen printing an integer without typecasting using the float specifier, but I think this is a different case here. I am printing a floating point number using the float specifier. It should print the correct value. Can anyone explain what is going on here?
source
share