The difference between structure and union is,
1. The amount of memory required to store a structure variable is the sum of the size of all the members.
On the other hand, in case of unions, the amount of memory required is always equal to that required by its largest member.
2. In case of structure, each member have their own memory space but In union, one block is used by all the member of the union.
Detailed Example:
1 2 3 4 5 6 | struct stu { char c; int l; float p; }; |
1 2 3 4 5 6 | union emp { char c; int l; float p; }; |
In the above example size of the structure stu is 7 and size of union emp is 4.
i talk to question you do answer
this helped me at a crucial time
short and sweet answer and everybody understand very easily
Because of giving example I clearly understand difference between structure & union about memory. Nice!
so buteful
plz give me answer difference between union and structure.