#include <stdio.h> union Value { int i; float f; char c; }; int main() { union Value v; v.i = 42; printf("As int: %d\n", v.i); v.f = 3.14f; // overwrites the same memory printf("As float: %.2f\n", v.f); return 0; }
Click Run to execute this code.