Multiple choice

In which of the following code fragments the variable ‘x’ is evaluated to 810 int x; a) x=32; b) x=16; c) x=38; d) x=36; x=x>>2; x=x>>1; x=x>>2; x=x>>2;

  1. Both a and b

  2. Both c and d

  3. Only a

  4. All codes

  5. None of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

>> is bitwise right shift operator.a)(32)10=(100000)2. After >>2 we get, (8)10=(001000)2b) (16)10=(010000)2. After >>1 we get, (8)10=(001000)2. This option is correct as we are getting ‘8’ after right shift by 2.