GATE CS 2025 Set 1 | Question 34

Programming & Data Structures › Pointers · NAT · 1 mark · Answer: 25

  1. Question 34Programming & Data Structuresnat1 mark
    Consider the C program:
    #include <stdio.h>
    void foo(int *p, int x){
        *p = x;
    }
    int main(){
        int *z;
        int a = 20, b = 25;
        z = &a;
        foo(z, b);
        printf("%d", a);
        return 0;
    }
    The output of the given C program is __________. (Answer in integer)

    Answer: 25

    Solution

    Answer: 25 z points to a. The call foo(z, b) passes this pointer and the value b = 25. Inside foo, *p = x writes 25 through the pointer, i.e. into a. So a becomes 25, and printf("%d", a) prints .

More GATE PYQ on Pointers

All GATE CS Programming & Data Structures PYQ →

Attempt GATE CS 2025 Set 1 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →