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
GATE CSE 2011 · Q22
Time
Char c[] = "GATE2011";
char *p = c;
printf("%s", p + p[3] - p[1]);Select one answerSingle correct
Solution
Official answer: C) 2011
Programming in CLet us trace the execution step by step:
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'
Pointer p points to the beginning of the array c (i.e., p = c).
Evaluate p[3] and p[1]:
p[3] is the character 'E', whose ASCII value is .
p[1] is the character 'A', whose ASCII value is .
Compute the offset:
The pointer passed to printf("%s", ...) is p + 4, which points to the subarray starting at index 4 (c[4]), containing "2011".
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.
Examiner trap
Find the ASCII difference between 'E' (p[3]) and 'A' (p[1]), then see where p + offset points.
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
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.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
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 CIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.