GATE / CS ARCHIVE

GATE CSE 2014 SET 1 / QUESTION 10

GATE CSE 2014 Set 1 Q10

Programming in C · Pointers & Memory · Full GATE CSE 2014 Set 1 paper

GATE 2014 Set 1, Q10 1 mark · MCQ
Report issue

Pointers & Memory

Question 10, GATE 2014: Consider the C program with stdio included: main(){ int i; int *pi=&i; scanf("%d",pi); printf("%d\n",i+5); }. Which statement is true? A: Compilation fails. B: A runtime error occurs. C: It prints five more than the address of i. D: It prints five more than the integer entered. Interpret the legacy main declaration under the intended historical C convention.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Our answer: D under the intended C execution assumptions

1. Method and setup. The address operator makes pi point to the existing integer object i. scanf requires precisely such a destination pointer for %d, so this is equivalent to passing &i. printf subsequently evaluates the integer expression i+5; it does not use the pointer’s numeric address.

2. Work through the result and its assumptions. pi is a valid pointer to i, so a successful scanf conversion stores the entered integer in i and printf displays i+5, D. Assume representable input and no signed overflow; the source also uses legacy implicit-int main syntax rather than modern int main(void). These routine source conventions matter for literal compilation.

Original paper, page 9 · Answer key