The GATE Grind

GATE 2015 CS (CS3) – Question 43

Programming and Data Structures · Programming in C · 2 marks · Numerical answer

What is printed?

#include <stdio.h>
int main(void) {
 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);
}

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: 140

Explanation

Initially ptr points at p[0]. Incrementing moves it to p[1], so ptr−p is one. That entry contains a+3, whose pointed-to element is forty. The two adjacent %d conversions print one followed immediately by forty, namely 140.

More Programming in C questions

All Programming in C questions →