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.24 Eki 2018
Read moreWhen would you use a union data type?
A union is a special data type available in C that allows to store different data types in the same memory location . You can define a union with many members, but only one member can contain a value at any given time. Unions provide an efficient way of using the same memory location for multiple-purpose.
Read moreIs using union bad practice?
It’s not bad practice , it just shouldn’t be a very common practice. There are valid reasons for using a union (e.g. aliasing or sometimes really tightly packing data where the actual types might not always be the same), but those are not the kinds of code you will write every day.1 May 2015
Read moreShould you use unions in C++?
Unions are moderately useful in C and largely useless in C++ . It would be correct to say that in C++ they’re a “remnant from C++ being based on C”, but not to say they’re “a remnant from the C only days” as if C++ supercedes C.25 Oca 2011
Read more