[prev] 79 [next]

Exercise 14: Union

What would be output if we did the following:

struct generic myVar;

// treat myVar as ???
myVar.vartype = IS_INT;
myVar.fval    = 3.14159;
printf("%d\n", myVar.ival);

// treat myVar as ???
myVar.vartype = IS_FLOAT;
myVar.ival    = 42;
printf("%0.5f\n", myVar.fval);