ProgrammingHardTCS NQT · Infosys

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Procedure p(Integer a[], Integer x)
    a[0] = a[0] + x
    x = x + 100
    a[1] = x
    return x
end procedure
Integer arr[3] = {4, 6, 8}, x = 1, r
r = p(arr, x)
Print arr[0], arr[1], x, r
(Arrays are passed by reference; integers by value.)
  1. A. 5 101 1 101
  2. B. 5 101 101 101
  3. C. 5 6 1 101
  4. D. 5 101 1 1

Correct answer: A. 5 101 1 101

a[0] becomes 5 and the local x becomes 101, so arr[1] = 101; the caller's x stays 1 and r = 101: 5 101 1 101.

More Pseudocode and Code Tracing questions

Exams that ask this topic