Skip to content
GATEiit

GATE CSE 2021 Set 2 Q20: Output of *(arr[1] + 9) for a 4×5 int array

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?

Try it: multiple choice: exactly one correct option

Select one option
Wrong answer costs 1/3 mark in GATE.
Show answer and explanation

Answer: C (official GATE 2021 final answer key)

Concept used: arr[1] decays to an int pointer to the first element of row 1; the 2-D array is stored row-major.

First step: arr[1] + 9 is 5 + 9 = 14 ints from the start of the array, i.e. row 2, column 4.

Full step-by-step solution

Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.

Share this question

WhatsAppDownload image

Source: official GATE 2021 Set 2 CS question paper and final answer key, organised by IIT Bombay. Question paper · Answer key