C Unions

C Union also store different data type as like structures. Union and structures are derived data type. Union is a collection of different type like structures. The only difference between them is allocation of memory. We can access only member at a time in union.
all Members share same memory location in Union. Structure store memory location differently for different variable.

 

Syntax of Union :-

union test
{
char name[60];
int rollno;
}t1,t2;

In the Above Example we will use union keyword and after that name of union. We have only two data type in union is char, int. we declared two variables t1,t2, they belong to test union.

or

union test

{
char name[60];
int rollno;
};

union test t1,t2;

   Example of Union.

   The difference between Structure and Union.

 

 




Follow Us

Contact Us

tutorialworldin@yahoo.com

Back to Top