Thursday, 1 July 2010

Unions

Unions are collection of different data types. Union is a keyword.

Union and structure in C  are same in concepts, except allocating memory for their members.

Structure allocates storage space for all its members separately.
Whereas, Union allocates one common storage space for all its members
We can access only one member of union at a time. We can’t access all member values at the same time in union. But, structure can access all member values at the same time.
This is because, Union allocates one common storage space for all its members. Where as Structure allocates storage space for all its members separately.
Many union variables can be created in a program and memory will be allocated for each union variable separately.

You may like the following posts:



Structures
Keywords

No comments:

Post a Comment