ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(12 & -12, 12 ^ 12 >> 1)
  1. A. 4 10
  2. B. 4 18
  3. C. 12 10
  4. D. 4 6

Correct answer: A. 4 10

12 & -12 isolates the lowest set bit, which is 4. Shift binds tighter than ^, so 12 >> 1 is 6 and 12 ^ 6 is 10.

More Python Programming questions

Exams that ask this topic