Note that the order in which the above program prints the bytes depends on the endianness (byte order) used by your computer. https://en.wikipedia.org/wiki/Endianness
That's quite clever: I didn't realise one could use a union like that :+)
I mean the value is stored with one type, but you use the other type to retrieve it .....
So that must mean that there is no check on whether the type requested via the access is the same as the type on storage. Obviously one has to have the right types / sizes to give a coherent result.
The union is only as big as necessary to hold its largest data member. The other data members are allocated in the same bytes as part of that largest member. The details of that allocation are implementation-defined, and it's undefined behavior to read from the member of the union that wasn't most recently written. Many compilers implement, as a non-standard language extension, the ability to read inactive members of a union.
The example shows some similar to what booradley60 had.
But then, further down:
If two union members are standard-layout types, it's well-defined to examine their common subsequence on any compiler.