Frequently Asked C Language Interview Question & Answers
What is difference between structure and union?
Structure:
-
Struct keyword is used to define a structure.
-
Members do not share memory in a structure.
-
Any member can be retrieved at any time in a structure.
-
Several members of a structure can be initialized at once.
-
Size of the structure is equal to the sum of the size of each member.
-
Altering the value of one member will not affect the value of another.
-
Stores different values for all the members.
Union:
-
Union keyword is used to define a union.
-
Members share the memory space in a union.
-
Only one member can be accessed at a time in a union.
-
Only the first member can be initialized.
-
Size of the union is equal to the size of the largest member.
-
Change in value of one member will affect other member values.
-
Stores same value for all the members.