GateAI
Programming in C

GATE CSE 2020 · Q22

NAT1 markMedium

Time

Consider the following C program.#include <stdio.h> int main() { int a[4][5]={{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18 , 19, 20}}; printf("%d ", *(*(a+**a+2)+3)); return(0); }The output of the program is _________.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 19

Programming in C

Let us evaluate the expression *(*(a + **a + 2) + 3) step by step:

  1. Evaluate `a`**:

    • a is a 2D array of type int[4][5].

    • In an expression, a decays to a pointer to its first row, int (*)[5].

    • *a gives the first row a[0], which decays to a pointer to a[0][0] (type int *).

    • **a dereferences *a, yielding the value at a[0][0], which is 11.

  2. Evaluate `a + a + 2`**:

    • Substitute **a = 1:

      offset=1+2=3\text{offset} = 1 + 2 = 3
    • a + 3 points to the 4th row, a[3] (type int (*)[5]).

  3. **Evaluate *(a + 3) + 3**:

    • *(a + 3) is equivalent to a[3], which decays to &a[3][0] (type int *).

    • Adding 33 shifts the pointer to &a[3][3].

  4. **Evaluate *(*(a + 3) + 3)**:

    • Dereferencing gives a[3][3].

    • Looking at row index 3: {16, 17, 18, 19, 20}:

      • a[3][0] = 16

      • a[3][1] = 17

      • a[3][2] = 18

      • a[3][3] = 19

Therefore, the program prints 19.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Programming in C previous year question is Q22 of the GATE CSE 2020 paper. Find more GATE CSE PYQs on Programming in C in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Programming in C PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Programming in C in GATE CSE

Programming in C has 74 GATE CSE PYQs across 25 papers from 2011 to 2026. 16 of them are 1-mark NAT questions like this one, and GATE CSE 2020 has 3.

How GATE tests Programming in C

More from GATE CSE 2020

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2020 · Q22 · NAT

Consider the following C program. #include int main() { int a[4][5]={{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18 , 19, 20}}; printf("%d ", *(*(a+**a+2)+3)); return(0); } The output of the program is …

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.