Sometimes you need to access multiple data types under a single name for easy manipulation.

For example you want to refer to address with multiple data like house number, street, zip code, country.

At that time C supports structure which allows you to wrap one or more variables with different data types.


A union is a variable which may hold members of different sizes and types.
The syntax for declaring a union is similar to that of a structure:

    union number{
      int number;
      double floatnumber;
    } anumber;

This defines a union called "number" and a variable of it called "anumber". Here, number is the name of the union, and acts in the same way as a tag for a structure.

Members of the union can be accessed in the following way:

The reference site for this content is