ProgrammingHardTCS NQT Advanced · Accenture

What will be the output of the following pseudocode? (ref means the argument is passed by reference; other parameters are copies)

What will be the output of the following pseudocode? (ref means the argument is passed by reference; other parameters are copies)
Procedure upd(Integer a, ref Integer b)
    a = a + b
    b = a * 2
End Procedure
Integer x = 3, y = 4
upd(x, y)
upd(y, x)
Print x, y
  1. A. 34 14
  2. B. 3 4
  3. C. 42 21
  4. D. 7 14

Correct answer: A. 34 14

First call: a = 3 + 4 = 7 and y (by reference) = 14. Second call: a is a copy of y = 14, a = 14 + 3 = 17, and x (by reference) = 34. Output 34 14.

More Pseudocode and Code Tracing questions

Exams that ask this topic