ProgrammingEasyAccenture · Cognizant pattern

What will be the output of the following pseudocode?

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

Correct answer: C. 4 6

a = 10, then b = 10 - 4 = 6, then a = 10 - 6 = 4. This is the classic swap without a third variable.

More Pseudocode and Code Tracing questions

Exams that ask this topic