A
union is a user-defined type whose members overlap in memory. Unlike a structure whose members occupy separate regions of memory, the union’s members all occupy the same memory region. The size of the union is equal to the size of its largest field. When declaring a union, we use the following syntax:
union some_name
{
type_name member_name_1;
type_name member_name_2;
// ...
};
To define and use a simple union having three fields, we write:
union MyUnion
{
char c;
int x;
double d;
};
int main(void)
{
union MyUnion u;
u.c = 'A';
printf("The ...