Skip to content

Unions

union label {
    int x;
    char y;
};

It is similar to a struct1 in spirit but difference is that, all the members share same overlapping memory.
The size of the union is determined by the size of the largest member it contains.

C_e_union_alignment.svg

The union shown above has size of 4 bytes.

References


  1. Read more about structs