Data Structures & AlgorithmsHardTCS NQT Digital · Python semantics

Problem: What does the following print?

Problem: What does the following print?
print(int('12', 8) + int('0x1f', 16))
  1. A. 43
  2. B. 31
  3. C. 41
  4. D. 21

Correct answer: C. 41

'12' in base 8 is 10, and '0x1f' in base 16 is 31, so the sum is 41. The trap 21 mistakes the base-8 digits as decimal.

More Coding Interview Problems questions

Exams that ask this topic