GateAI
Programming in C

GATE CSE 2011 · Q22

MCQ1 markMedium

Time

What does the following fragment of C program print?Char c[] = "GATE2011"; char *p = c; printf("%s", p + p[3] - p[1]);

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: C) 2011

Programming in C

Let us trace the execution step by step:

  1. The character array c is initialized with the string "GATE2011":

    • c[0] = 'G'

    • c[1] = 'A'

    • c[2] = 'T'

    • c[3] = 'E'

    • c[4] = '2'

    • c[5] = '0'

    • c[6] = '1'

    • c[7] = '1'

    • c[8] = '\0'

  2. Pointer p points to the beginning of the array c (i.e., p = c).

  3. Evaluate p[3] and p[1]:

    • p[3] is the character 'E', whose ASCII value is 6969.

    • p[1] is the character 'A', whose ASCII value is 6565.

  4. Compute the offset:

    p[3]−p[1]=69−65=4p[3] - p[1] = 69 - 65 = 4
  5. The pointer passed to printf("%s", ...) is p + 4, which points to the subarray starting at index 4 (c[4]), containing "2011".

  6. Therefore, printf prints the string starting from c[4], which is 2011.

Hence, option (C) is correct.

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 2011 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. 20 of them are 1-mark MCQs like this one, and GATE CSE 2011 has 2.

How GATE tests Programming in C

More from GATE CSE 2011

Share this solution

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

GateAI solution cardGATE CSE 2011 · Q22 · MCQ

What does the following fragment of C program print? Char c[] = "GATE2011"; char *p = c; printf("%s", p + p[3] - p[1]);

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.