ProgrammingHardGATE CS · Product company OA

What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs aligned to their widest member with no packing pragma)? #include <stdio.h> void reverseArr(int *a, int n) { for (int i = 0; i < n / 2; i++) { int t = a[i]; a[i] = a[n - 1 - i]; a[n - 1 - i] = t; } } int main(void) { int arr[5] = {1, 2, 3, 4, 5}; reverseArr(arr, 5); printf("%d %d %d %d %d", arr[0], arr[1], arr[2], arr[3], arr[4]); return 0; }

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

Correct answer: B. 5 4 3 2 1

The function swaps elements from both ends toward the middle, reversing the array in place: {5,4,3,2,1}.

More C Programming questions

Exams that ask this topic