The GATE Grind

GATE 2011 CS (CS1) – Question 32

Programming and Data Structures · Programming in C · 1 mark · Multiple choice

What is printed?

char c[]="GATE2011";
char *p=c;
printf("%s",p+p[3]-p[1]);
  1. GATE2011
  2. E2011
  3. 2011
  4. 011

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (C) 2011

Explanation

Under the paper’s ASCII convention, p[3]=E and p[1]=A differ by 69−65=4. The argument is p+4, pointing to the substring after GATE. Printing that null-terminated suffix yields 2011, C.

More Programming in C questions

All Programming in C questions →