Advertisement Remove all ads

Define Union. Compare Structure and Union. - Structured Programming Approach

Define union. Compare Structure and Union. 

Advertisement Remove all ads

Solution

Union :- A union is a special data type available in C that allows storing different data types in the same memory location.  

  Structure Union 
Keyword The keyword ‘struct’ is used to define a structure. The keyword ‘union’ is used to define a union.
Size When a variable associated with a structure, the compiler allocates the memory for each member. The size of structure is greater than or equal to the sum of sizes of its members. When a variable associated with a union, the compiler allocates the memory by considering the size of the largest memory. Hence, The size of union is equal to the size of largest members.
Memory Each member within a structure is assigned and unique storage area of location. Memory allocated is shared by individual members of union.
Value Altering Altering the value of a member will not affect other members of the structure Altering the value of any of the member will alter other member values.
Accessing members Individual member can be accessed at a time. Only one member can be accessed at a time.
Initializing Members Several members of a structure can initialize at once. Only the first member of a union can be initialized.
Concept: Union
  Is there an error in this question or solution?
Advertisement Remove all ads
Advertisement Remove all ads
Advertisement Remove all ads
Share
Notifications

View all notifications


      Forgot password?
View in app×