C Union

An union is a collection of different types of members in a single entity.
By using union, we can create user-defined data type.
In union all members share memory location.
In implementation when we are manipulating the data for all member variable, then go for structures, if we are using only one member then go for an Union.
When we are working union manipulation will take place for only one member, if we are multiple members then actual data will be fast.

Syntax:

union tagname
{
datatype member1;
datatype member2;
datatype member3;
———–
———–
———–
}

Example:

union emp
{
int id;
char sname[39];
int sal;
};

Powered by k2schools