GATE Computer ScienceHardGATE CSE · TCS

void f(int a[], int n) { a[0] = n; n = a[1]; a = a + 1; a[0] = 99; } int main() { int x[3] = {1, 2, 3}; int m = 5; f(x, m); printf("%d %d %d %d", x[0], x[1], x[2], m); } What is printed?

  1. A. 5 2 3 2
  2. B. 5 99 3 2
  3. C. 5 99 3 5
  4. D. 1 99 3 5

Correct answer: C. 5 99 3 5

a[0] = n sets x[0] = 5. n = a[1] changes only the local copy, and a = a + 1 moves only the local pointer, so a[0] = 99 writes x[1] = 99. m stays 5.

More Programming and Data Structures (GATE) questions

Exams that ask this topic