Sail E0 Webinar
Question

What will be output if you compile following c code ?


#include<stdio.h>
void main()
{
struct sample
{
unsigned a:1;
unsigned b:4;
}v={0,15};
unsigned *vptr=&v.b;
printf("%d %d",v.b,*vptr);
}


Options:
A .  Compile Error
B .  0 0
C .  15 15
D .  None of these
Answer: Option A

Since we cannot take the address of a bit field variable i.e. Use of pointer to access the bit fields is prohibited. Also we cannot use 'scanf' function to read values into a bit field as it requires the address of a bit field variable. Also array of bit-fields are not permitted and a function cannot return a bit field.



Was this answer helpful ?
Next Question

Submit Solution

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

Latest Videos

Latest Test Papers