ProgrammingVery hardJEE Main · CAT placement

What is printed?

What is printed?
x = 12
print(x & -x, x ^ (x - 1), (x & (x - 1)) == 0, -x & x == x & -x)
  1. A. 4 7 True True
  2. B. 4 8 False True
  3. C. 4 7 False True
  4. D. 12 7 False True

Correct answer: C. 4 7 False True

x & -x isolates the lowest set bit, which is 4. x ^ (x - 1) gives 7 because it flips the trailing bits. In the comparison, & binds tighter than ==, so both sides are the same value, which makes the last check True.

More Python Programming questions

Exams that ask this topic