0
819views
written 6.0 years ago by |
Like structures, a union can be declared using the keyword union as follows:
union item
{
int m;
float x;
char c;
} code;
This declares a variable code of type union item. The compiler allocates a piece of storage that is large enough to hold the largest variable type in the union.
To access a union member, we can use the same syntax that we use for structure members. That is,
code.m
code.x
code.c