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

Programmingway@Eklavya Technosys!: Class - 7 A or B | Computer | 100 Questions!

Programmingway@Eklavya Technosys!: Class - 7 A or B | Computer | 100 Questions! :  1) What is digital citizenship? 2) What is a digital citi...