The GATE Grind

GATE 2021 CS (CS2) – Question 20

Programming and Data Structures · Arrays · 1 mark · Multiple choice

What is printed by this source C program under its contiguous-array addressing model?

#include <stdio.h>
int main() {
 int arr[4][5],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;
}
  1. 14
  2. 20
  3. 24
  4. 30

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (C) 24

Explanation

In the source’s linear row-major address calculation, arr[1] starts at overall element five. Adding nine reaches overall element fourteen, row two,column four, whose value is twenty-four, C. Strict ISO C pointer arithmetic does not permit walking beyond the five-element row subarray this way, so the published answer relies on the intended flat-address interpretation rather than portable defined behaviour.

More Arrays questions

All Arrays questions →