Interview Question
0of 0 votesmain(){
union d{
unsigned int a:1;
unsigned int b:3;
unsigned c:2;};
union d aa;
aa.b=6;aa.c=2;aa.a=1;
printf("%d %d %d",aa.a,aa.b,aa.c);}
What does the above code output?
Country: United States
there would be max 3 bit.
aa.b=6=110
aa.c=2=10
aa.a=1
now final bit 111
so aa.a=1
aa.b=11=3
aa.c=111=7
aa.b=1=001
aa.c=3=11
aa.a=7(actually aa.a is of i bit so it take only 1)=1
so the final bit is 011
so aa.a=1=1
aa.b=011=3
aa.c=11=3

Answer would be 1 7 3, check
- Luv on July 03, 2012 Edit | Flag Reply