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.
Description :
This is the one stop educational site for all Electronic and Computer students. If you want to learn something new then we are here to help. We work on Microcontroller projects, Basic Electronics, Digital electronics, Computer projects and also in basic c/c++ programs.
#Home #Sitemap #Resources #Terms of Use
Copyright©2012 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com