Thursday, December 25, 2014

DIFFERENCE BETWEEN STRUCTURE & UNION

Structure take individual memory space for each variable while union takes largest memory space & all variable share its. 

Example of Structure
struct emp
{
 int code;
 char name[20];
 float sal;
};
intà2bytes
stringà20bytes
floatà4bytes

Total Memory occupiedà26bytes

Example of Union
union emp
{
 int code;
 char name[20];
 float sal;
};

Total Memory occupied à20bytes

No comments:

Post a Comment