Sail E0 Webinar
Question

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));
}


Options:
A .  6 30
B .  8 40
C .  9 45
D .  None of these
Answer: Option B

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 ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers