ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
print(5 & 3, 5 | 3, 5 ^ 3, ~5, 5 << 2, -5 >> 1)
  1. A. 1 7 6 -6 20 -2
  2. B. 1 7 6 -6 20 -3
  3. C. 1 7 6 -5 20 -3
  4. D. 1 7 6 -6 10 -3

Correct answer: B. 1 7 6 -6 20 -3

~x equals -x - 1, so ~5 is -6, and >> is an arithmetic shift that floors, so -5 >> 1 is -3, not the truncated -2.

More Python Programming questions

Exams that ask this topic