ProgrammingModerateCapgemini · Infosys pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer a = 1, b = 2, c = 3
a = b + c
b = a - b * c
c = a * b - c
Print a + b + c
  1. A. -4
  2. B. -2
  3. C. 6
  4. D. 4

Correct answer: A. -4

Each line uses the values updated just before it: a = 5, b = 5 - 2 × 3 = -1, c = 5 × (-1) - 3 = -8. Sum = 5 - 1 - 8 = -4. The usual slip is using the old b = 2 in the last line, which gives c = 7 instead of -8.

More Pseudocode and Code Tracing questions

Exams that ask this topic