// CS 1621 Fall 2005 // Unions in C++ #include using namespace std; union wacky // Union declaration { int i; // i and f share memory locations float f; }; int main() { wacky w; w.i = 100; // Note that when accessed as the "wrong" cout << w.i << endl; // type, the data is garbage -- this can cout << w.f << endl; // be risky, so programmer must be careful w.f = 100; cout << w.i << endl; cout << w.f << endl; }