UnionsΒΆ

A union is a kind of polymorphic type, defined and used in C with syntax identical to structures in nearly every way except for using the keyword union instead of struct. The critical difference in representation is that, where a structure makes space for all of the members, with any needed alignment and padding considerations, a union puts all of its members at offset zero and has the size of the largest member. That is to say, all of the members overlap in memory. Obviously, only one of the members of a union can actually be represented at once, but which member is valid can be different at different times. This gives unions the ability to represent a choice among different types at runtime.

You have attempted of activities on this page