From the C11 specification, §6.5.2.3 note 95:
If the member used to read the contents of a union object is not the same as the member last used to
store a value in the object, the appropriate part of the object representation of the value is reinterpreted
as an object representation in the new type as described in 6.2.6 (a process sometimes called ‘‘type
punning’’). This might be a trap representation.
This says that what you're doing is allowed, but also implies that the value you read may not be what you expect (for example by writing to an int
member and reading from a float
member).
There's also the caveat about trap representation values in which case the behavior will be undefined. For two's complement systems (which is the vast majority of all computers the last couple of decades) this isn't an issue with integer values though.
In your case the result will depends very much on the platforms endianness. Either you will get the value you write (1
) or you will get 0
.