In the following code
#include<stdio.h>
int main()
{
union myUnion
{
int intVar;
char charVar;
float floatVar;
};
union myUnion localVar;
localVar.intVar = 10;
localVar.charVar = 'A';
localVar.floatVar = 20.2;
printf("%d ", localVar.intVar);
printf("%c ", localVar.charVar);
printf("%f ", localVar.floatVar);
}
I understand that union can hold only one value at a time. So when I assign char value, int would be overwritten, n then when I assign floatValue, char would be overwritten. So I was expecting some garbage values for int and char variables and 20.200000 for float variable as it was last value to be assigned. But following is the output I'm getting on VS Express as well as gcc
1101109658 Ü 20.200001
unable to understand why float value is changed ?