Union


A union is a derived data type like structure , so union also can store different data types.
Syntax:-
   union tag_name
   {
   type 1;
   type 2;
   } variable;

Difference between structure and union.

StructureUnion
The keyword struct is used to define a structure.The keyword union is used to define a union.
When a variable is associated with a structure the compiler allocates the memory for each member. The sizeof structure is greater than or equal to the sum of size of its members the smaller members may end with unused slack bytes.When a variable is associated with a union, the compiler allocates the memory by considering the size of the largest member. So size of union is equal to the size of largest member .
Each member within a structure is assigned unique storage area .Memory allocated is shared by individual members of union.
Structure helps to construct a complex data type which is more meaningful.The address is same for all the members of a union the indicates that every members of union.