GATE Computer ScienceHardGATE CS (PYQ pattern)

With int i = 2 and the array A = [0, 3, 5, 7, 9, 11, 13] (indices from 0), the call f(A[i], i) is made to void f(p, q) { i = i + 1; p = p + 10; q = q * 2; } Parameters are passed by name (call by name: argument expressions are re-evaluated at each use). What are the values after the call returns?

  1. A. A[2..4] = 5, 7, 9; i = 3
  2. B. A[2..4] = 5, 17, 9; i = 6
  3. C. A[2..4] = 15, 7, 9; i = 6
  4. D. A[2..4] = 15, 7, 9; i = 4

Correct answer: B. A[2..4] = 5, 17, 9; i = 6

With call by name, p is the text A[i], re-evaluated after i = i + 1, so the element updated is A[3]; q is i itself so i ends at 6.

More Compiler Design questions

Exams that ask this topic