Difference between Structure and Union

Structure Union
Keyword : struct Keyword : union
Each member in a structure occupies and uses its own memory space All the members of a union use the same memory space
More memory space is required since each member is stored in a separate memory locations Less memory space is required since all member is stored in the same memory locations
All the members of a structure can be initialized Only the first member of an union can be initialized
The variables that make up the structure are called Structure variable The variables that make up the union are called union variable
Individual structure elements are referred through the use of .(dot or membership) operator Individual union elements are referred through the use of .(dot or membership ) operator
Structure is a user-defined data type. Union is a user-defined data type.
Possible to have one structure within another structure Unions within union is possible

Comments