Question
#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);
}
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);
}
Answer: Option D
Was this answer helpful ?
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 ?
Submit Solution