Question
#include<stdio.h>
struct A
{
int i;
float f;
union B
{
char ch;
int j;
}temp;
}temp1;
void main()
{
struct A temp2[5];
printf("%d %d",sizeof(temp1),sizeof(temp2));
}
What will be output if you compile following c code ?
#include<stdio.h>
struct A
{
int i;
float f;
union B
{
char ch;
int j;
}temp;
}temp1;
void main()
{
struct A temp2[5];
printf("%d %d",sizeof(temp1),sizeof(temp2));
}
Answer: Option B
Was this answer helpful ?
Since int (2 bytes) + float (4 bytes) = (6 bytes) + Largest among union is int (2 bytes) is equal to (8 bytes). Also the total number of bytes the array 'temp2' requires :
(8 bytes) * (5 bytes) = (40 bytes).
Was this answer helpful ?
Submit Solution