Follow us on: facebook twitter linkedin

PROGRAMING

Union in C

Post by : John Deo
Post date: 2023-12-14 14:25:38

Read time : 5 minute
Total views: 355 times
hero-img

Union

Union mean container of various type of data. We can store string array integer float type data in union. For declare a union type must be use union reserve word. 

 

Example 

union empDetails
{
   int emp_id;
   char emp_name[50];
   char birth_date[20];
}

 

union empDetails emp1;

 

Structure vs Union

Main differrence between union and structure is. During program execution or declaring time union hold only one largest amount data from union. Suppose we declare two data from union

  1. emp1.name variable.
  2. emp1.birth_date.

Finally we will found emp1.name variable.

Share by:

Keep exploring

Read what excites, achieves and moves us Read what excites, achieves and moves us