Sail E0 Webinar
Question

What will be output if you compile following c code ?


#include<stdio.h>
void main()
{
static struct my_struct
{
unsigned a:1;
int i;
unsigned b:4;
unsigned c:10;
}v={1,10000,15,555};
printf("%d %d %d %d",v.a,v.b,v.c,v.d);
printf("\nSize=%d bytes",sizeof v);
}


Options:
A .  Compile Error
B .  1 10000 15 555 size = 4 bytes
C .  10000 1 15 555 size = 4 bytes
D .  10000 1 15 555 size = 5 bytes
Answer: Option D

Here the bit field variable 'a' will be in first byte of one word, the variable 'i' will be in the second word and the bit fields 'b' and 'c' will be in the third word. The variables 'a', 'b' and 'c' would not get packed into the same word. [NOTE: one word=2 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