The GATE Grind

GATE 2014 CS (CS1) – Question 20

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

Consider this C program:

#include <stdio.h>
main() {
int i;
int *pi = &i;
scanf("%d", pi);
printf("%d\n", i+5);
}

Which statement is TRUE?

  1. Compilation fails.
  2. Execution causes a run-time error.
  3. The printed value is 5 more than the address of i.
  4. The printed value is 5 more than the integer entered.

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (D) The printed value is 5 more than the integer entered.

Explanation

pi holds the address of i, so scanf with pi stores the entered integer into i. The printf argument is i+5, giving **five more than the entered integer, D**. It does not print pointer arithmetic. This uses the source’s historical C dialect allowing the implicit-int main declaration.