retagged by
330 views
2 votes
2 votes
#define Raining 0x04

int bring_flower(unsigned u) {
	return (u & Raining == 0) ? 0 : 1;
}

int main() {
	
	printf("%d\n",bring_flower(0x1B));
	return 0;

}

Above program $\rightarrow$

  • Always returns 0
  • 0 when the Third rightmost bit of the input to bring_flower is 0
  • 1 when the Third rightmost bit of the input to bring_flower is 1
  • Always returns 1
retagged by

1 Answer

Best answer
6 votes
6 votes
Raining : 4        00100

u =  27              11011

It will always return 1 answer

return ( u & Raining == 0) ? 0 : 1;

Here,    ==  solve first then &  solve   

Raning == 0  ,   will give  0

Then ( u & 0 )   will be  false , means it will  go for the second part of ternary

It will always return  1 , if u is non zero.

Then option D is corrrect : Always return 1

return ( (u & Raining) == 0) ? 0 : 1;     ( if we write  u & Raining in brackets )  then bitwise & of Raing and u will be zero , in that case it will go for the first part of ternary.  But this is not the case.
selected by

Related questions