C unions allow data members which are mutually exclusive to share the same memory . This is quite important when memory is valuable, such as in embedded systems. Unions are mostly used in embedded programming where direct access to the memory is needed.
Read moreWhy do we use union in C++?
Union is a user-defined datatype. All the members of union share same memory location. Size of union is decided by the size of largest member of union. If you want to use same memory location for two or more members , union is the best for that.
Read moreAre unions bad in C?
Unions are moderately useful in C and largely useless in C++. … Yes, there are other solutions to the same problem (mainly casting between pointer types), but unions are often cleaner and better self-documenting.
Read more