What is union & explain its use?

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

What is C union size?

When we declare a union, memory allocated for a union variable of the type is equal to memory needed for the largest member of it, and all members share this same memory space. In above example, “char arr[8]” is the largest member. Therefore size of union test is 8 bytes .

Read more

How does C union work?

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 more