1. It allocates memory equal to sum of memory allocated to its each individual member.
2.each member have their own memory space.
3. structure can not be implemented in shred memory.
4. it has less Ambiguity.
5. Self referential structure can be implemented in data structure.
6. All members if structure can be accessed at a time.
You can watch Structure Video here
1.It allocates piece of memory that is Large enough to hold the Largest variable of type in union.
2. one block is used by all the members of union.
3. Union is the Best environment where memory is shared.
4. as memory is shared, Ambiguity is more in union.
5. self ref. union can not be implemented.
6. only one member is accessed at a time.
You can watch Union Video here
structure element 1;
structure element 2;
structure element n;
union element 1;
union element 2;
union element n;
In union members share memory and the memory allocated is equal to the memory allocation of data member which occupies maximum space.
In structure data members do not share memory they have their own memory and are contiguously stored.The memory allocated is equal to the sum of byte allocation of individual members.
+ point:We can access any member at any given time without data corruption.
-point:Squeezes more memory space.
+ point:Occupies less memory.
- point:We can access only one union member at a time without data loss,since the members share memory.
1. union allocates the memory equal to the maximum memory required by the member of the union but structure allocates the memory equal to the total memory required by the members.
2. In union, one block is used by all the member of the union but in case of structure, each member have their own memory space.
3. union is best in the environment where memory is less as it shares the memory allocated.But structure can not implemented in shared memory.
4. As memory is shared,ambiguity are more in union,but less in structure.
5. self referencial union can not be implemented in any datastructure ,but self referencial structure can be implemented.