When 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 more

Is 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 more