Question:

Consider the following ANSI C program. 

#include <stdio.h>
int main(){
    int arr[4][5];
    int i, j;
    for (i=0; i<4; i++){
        for (j=0; j<5; j++){
            arr[i][j] = 10*i + j;
        }
     }
    printf("%d", *(arr[1] + 9));
    return 0;
} 

What is the output of the above program? 

 

Show Hint

In 2D arrays, pointer arithmetic continues linearly in row-major order, so adding beyond a row moves into the next row.
Updated On: Dec 30, 2025
  • 14
  • 20
  • 24
  • 30
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

Step 1: Understand array initialization.
The array \(\texttt{arr[4][5]}\) is filled using the formula \[ arr[i][j] = 10i + j. \] So the second row (\(i = 1\)) becomes: \[ arr[1] = \{10, 11, 12, 13, 14\}. \]

Step 2: Pointer interpretation of \(\texttt{arr[1]}\).
In C, \(\texttt{arr[1]}\) points to the first element of the second row, i.e., \(&arr[1][0]\).

Step 3: Evaluate the expression \(\texttt{*(arr[1] + 9)}\).
Since each row has 5 elements, adding 9 moves the pointer as follows: \[ arr[1] + 9 = &arr[1][9] = &arr[2][4]. \]

Step 4: Find the value at \(\texttt{arr[2][4]}\).
Using the formula: \[ arr[2][4] = 10 \times 2 + 4 = 24. \]

Step 5: Final output.
The \(\texttt{printf}\) statement prints the value \(\texttt{24}\).

Was this answer helpful?
0
0

Questions Asked in GATE CS exam

View More Questions