ProgrammingVery hardTCS NQT Advanced · Capgemini

What will be the output of the following pseudocode? (operands are evaluated strictly left to right)

What will be the output of the following pseudocode? (operands are evaluated strictly left to right)
Integer a = 7, b = 3
a = a + b - (b = a)        // the inner assignment happens when that operand is evaluated
Print a, b
  1. A. 3 7
  2. B. 7 3
  3. C. 10 7
  4. D. 4 7

Correct answer: A. 3 7

Evaluated left to right: a + b = 10 is computed first, then (b = a) sets b to 7 and yields 7. So a = 10 − 7 = 3 and b = 7: the values are swapped, 3 7.

More Pseudocode and Code Tracing questions

Exams that ask this topic