ProgrammingHardTCS NQT · Infosys

int a[6] = {1, 2, 3, 4, 5, 6}; int *p = a, *q = a + 5; while (p < q) { int t = *p; *p++ = *q; *q-- = t; } What is a[1] afterwards?

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

Correct answer: B. 5

The loop reverses the array, giving {6, 5, 4, 3, 2, 1}. The element at index 1 becomes 5.

More C Programming questions

Exams that ask this topic