Data Structures & AlgorithmsHardTCS NQT Digital · Python semantics

Problem: What does the following print?

Problem: What does the following print?
x = 5
x <<= 2
x |= 1
print(x)
What is printed?
  1. A. 20
  2. B. 21
  3. C. 22
  4. D. 25

Correct answer: B. 21

5 << 2 = 20, and 20 | 1 = 21. The trap 25 comes from computing 5 * 5 for a shift.

More Coding Interview Problems questions

Exams that ask this topic