Sail E0 Webinar
Question

What are the largest values that can be assigned to each of the bit fields defined in this question


#include<stdio.h>
void main()
{
static struct my_struct
{
unsigned a:1;
unsigned b:2;
unsigned c:3;
unsigned d:4;
unsigned :6; // Fill out first word
}v={1,2,7,12};
printf("%d %d %d %d",v.a,v.b,v.c,v.d);
printf("\nSize=%d bytes",sizeof v);
}


Options:
A .  a=0 b=2 c=3 d=4
B .  a=1 b=2 c=7 d=15
C .  a=1 b=3 c=7 d=15
D .  None of these
Answer: Option C

a=1  (1 bit: 0 or 1)
   b=3  (2 bits: 00 or 01 or 10 or 11),
   c=7  (3 bits: 000 or 001 or 010 or 011 or 100 or 101 or 110 or 111)
   d=15 (4 bits: 0000 or 0001 or 0010 or 0011 or 0100 or 0101 or 0110 or 0111 or 1000 or
      1001 or 1010 or 1011 or 1100 or 1101 or 1110 or 1111)




Was this answer helpful ?
Next Question

Submit Solution

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

Latest Videos

Latest Test Papers