GateAI
Programming in C

GATE CSE 2015 Set 3 · Q26

NAT1 markMedium

Time

Consider the following C program.#include<stdio.h> int main( ) { static int a[ ] = {10, 20, 30, 40, 50}; static int *p[ ] = {a, a+3, a+4, a+1, a+2}; int **ptr = p; ptr++; printf("%d%d", ptr-p, **ptr); }The output of the program is ____________.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 140

Programming in C

Let us trace the program step by step:

  1. Array a contains five integers:

    • a[0] = 10, a[1] = 20, a[2] = 30, a[3] = 40, a[4] = 50

  2. Array p is an array of pointers to int:

    • p[0] = a (points to a[0])

    • p[1] = a + 3 (points to a[3])

    • p[2] = a + 4 (points to a[4])

    • p[3] = a + 1 (points to a[1])

    • p[4] = a + 2 (points to a[2])

  3. ptr is a pointer to pointer to int, initialized to p (i.e., &p[0]).

  4. ptr++ increments ptr so that it points to p[1].

  5. In printf("%d%d", ptr-p, **ptr):

    • ptr - p: Pointer subtraction gives the difference in elements, which is 1−0=11 - 0 = 1.

    • **ptr: *ptr evaluates to p[1] (which is a + 3), and *(*ptr) dereferences that pointer to get a[3] = 40.

Printing %d%d without spaces between them outputs 140.

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 Q26 of the GATE CSE 2015 Set 3 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 2015 Set 3 has 4.

How GATE tests Programming in C

More from GATE CSE 2015 Set 3

Share this solution

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

GateAI solution cardGATE CSE 2015 Set 3 · Q26 · NAT

Consider the following C program. #include int main( ) { static int a[ ] = {10, 20, 30, 40, 50}; static int *p[ ] = {a, a+3, a+4, a+1, a+2}; int ptr = p; ptr++; printf("%d%d", ptr-p, ptr); } 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.