GATE Computer ScienceVery hardGATE CS (PYQ pattern)

In C99, int x = −37 (32-bit two's complement), and this implementation's >> on negative values is an arithmetic shift. What are x / 4, x >> 2 and x % 4?

  1. A. -10, -10 and 3
  2. B. -9, -9 and -1
  3. C. -10, -9 and 3
  4. D. -9, -10 and -1

Correct answer: D. -9, -10 and -1

C99 division truncates toward zero: −37/4 = −9.25 → −9, and x % 4 = x − 4·(x/4) = −37 + 36 = −1. The arithmetic shift floors: −37 >> 2 = ⌊−9.25⌋ = −10. Shifting is not the same as dividing a negative number by a power of two.

More Computer Organization and Architecture questions

Exams that ask this topic