📜  门| GATE CS 2020 |第 54 题(1)

📅  最后修改于: 2023-12-03 14:58:20.915000             🧑  作者: Mango

GATE CS 2020 - Question 54

Introduction

This question from the GATE CS 2020 exam asks about the output of a given C program. The program includes a pointer and a function that modifies the pointer. The question tests the candidate's understanding of pointers and function calls in C.

The Program
#include <stdio.h>

void modify(int *p)
{
    *p += 10;
}

int main()
{
    int i = 0;
    int *p = &i;
    modify(p);
    printf("%d %d\n", i, *p);
    return 0;
}
Explanation

The program first declares an integer i and a pointer p that points to i. The modify function takes a pointer argument and adds 10 to the value pointed by the pointer. In the main function, the modify function is called with p as an argument. This modifies the value of i. Then, the program prints the value of i and the value pointed by p.

Since modify modifies the value pointed by p, both i and *p are modified to 10. Therefore, the output of the program will be:

10 10
Conclusion

This question tests the candidate's understanding of pointers and function calls in C. The program demonstrates the use of a pointer and a function that modifies the value pointed by the pointer. The candidate must understand how pointers work and how they can be used as function arguments.