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
Related User Ask Questions
Which of the following is not a primary function of a Bank?
A. Granting Loans
B. Collecting Cheques/Drafts customers
C. Facilitating import of goods
D. Issuing Bank Drafts
A. Regulatory jurisdictional fight between SEBI and IRDA
B. They don’t offer better tax benefits
C. They offer lesser returns compared to traditional insurance policies
D. All of the above
The Chameli Devi Jain Award is given for an outstanding woman ____?
A. Scientist
B. Reporter
C. Player
D. Teacher
Join The Discussion