ProgrammingModerateCapgemini · Infosys pattern

What will be the output of the following pseudocode? (Arrays are indexed from 0.)

What will be the output of the following pseudocode? (Arrays are indexed from 0.)
Integer arr[6] = {1, 2, 3, 4, 5, 6}
for (each i from 0 to 2)
    swap(arr[i], arr[5 - i])
end for
Print arr[0], arr[2], arr[5]
  1. A. 6 5 1
  2. B. 6 3 1
  3. C. 6 4 1
  4. D. 1 3 6

Correct answer: C. 6 4 1

Swapping the pairs (0, 5), (1, 4) and (2, 3) reverses the array to {6, 5, 4, 3, 2, 1}. So arr[0] = 6, arr[2] = 4, arr[5] = 1.

More Pseudocode and Code Tracing questions

Exams that ask this topic