almost 9 years ago
The keyword struct is used to define a structure.
The keyword union is used to define a union.
In structure each member has its own storage location.
All members of union uses a single shared memory location which is equal to the size of its largest data member.
Changing the value of a member will not affect other members of the structure.
Changing the value of any of the member will Change other member values.
Individual member can be accessed at a time.
Only one member can be accessed at a time.
Any number of members can initialize at once.
Only the first member of a union can be initialized.
All variables can be directly accessed as each member has its own storage location.
Only the last entered variable can be directly accessed as only the last added data to the union will exist in the memory.
For Example:-
struct emp
{
char A; //size 1 byte
float B; //size 4 byte
}e;
Total number of bytes allocated are 5.
union emp
char A;
float B;
Total number of bytes allocated are 4.
Starting with Chrome version 45, NPAPI is no longer supported for Google Chrome. For more information, see Chrome and NPAPI (blog.chromium.org).
Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets.
Chrome Version Support
Are you sure, you want to delete this comment?
Sign up using
0 Comment(s)