Nirmani Wijesinghe
Nirmani Wijesinghe
7 years ago

Write a c program to define a union and a structure both having exactly the same members, using the sizeof operator,print the size structure variable as well as the union variable

Solution(By Examveda Team)


union uData {
int i;
float f;
char str[20];
};
struct sData{
int i;
float f;
char str[20];
};
int main ( ) {
union uData uData;
struct sData sData;
printf( "Memory size occupied by union data : %d", sizeof(uData)));
printf( "Memory size occupied by structure data : %d", sizeof(sData)));
return 0;
}

Output :
Memory size occupied by union data : 20
Memory size occupied by structure data : 28

This Question Belongs to User Ask Question >> Miscellaneous

Join The Discussion

Related User Ask Questions