Skip to content
Official PYQ · 2014

GATE CS 2014 Set 1 Q10 — Programming in C

Explain with AI

Consider the following program in C language:

#include <stdio.h>

main()
{
   int i;
   int*pi = &i; 
   
   scanf("%d",pi);
   printf("%d\n", i+5);
}

Which one of the following statements is TRUE?

Choose one option
View worked solution

Answer: D

Let us analyze the execution of the given C program step-by-step:

  1. Variable Declaration:
    int i;
    This declares an integer variable i.
  2. Pointer Initialization:
    int* pi = &i;
    This declares an integer pointer pi and initializes it with the address of i (i.e., &i). Thus, pi points to the memory location of i.
  3. Reading Input:
    scanf("%d", pi);
    The scanf function expects the address of the variable where the input integer should be stored. Since pi holds the address of i (equivalent to &i), the integer entered by the user is successfully stored in the variable i.
  4. Printing Output:
    printf("%d\n", i + 5);
    This prints the value stored in i plus 55.

Thus, the program compiles and executes successfully, printing a value that is 55 more than the integer value entered by the user.

Therefore, the correct option is D.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Programming in C questions