Difference between structure and union

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:

StructureUnion
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 structureAltering the values of the member will affect the other member of the structure

Relevant Posts:



Categories: C Language

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: