ProgrammingHardTCS Digital · Capgemini

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
// Integer16: 16-bit signed integers in two's complement; results wrap around
Integer16 x = 30000
x = x + 30000
Print x
  1. A. 60000
  2. B. -32768
  3. C. 27232
  4. D. -5536

Correct answer: D. -5536

A 16-bit signed integer holds −32768 to 32767. 60000 exceeds that, so it wraps by 65536: 60000 − 65536 = −5536.

More Pseudocode and Code Tracing questions

Exams that ask this topic