Both structure and union are user-defined data types that contain data of different types. A few of the important differences between structure and union are:
Structure | Union |
Each member of the structure has its own memory location. | All the members of the union share the same memory address. |
The size of the structure is the sum of the size of each member present. | The size of the union is the size of the largest member present in the union. |
All members can be initialized with the values at once and so can be accessed. | Only one member can be initialized and accessed at a time. |
Altering the values of the member will not affect the other members of the structure | Altering the values of the member will affect the other member of the structure |
Relevant Posts:
Categories: C Language
Leave a Reply