#include 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)
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2025 Set 1 · Q34
Time
#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)Your answerNumerical answer
Solution
Official answer: 25
Programming in CLet us trace the execution of the program step by step:
Inside main(), integer variables a and b are initialized with values 20 and 25, respectively.
The pointer z is assigned the address of a (z = &a), meaning z points to a.
The function call foo(z, b) passes the pointer z (address of a) by value to the pointer parameter p, and the value of b (25) to x.
Inside foo(), the statement *p = x; dereferences pointer p and assigns the value 25 to the memory location pointed to by p (which is variable a). Thus, a becomes 25.
After foo() returns, printf("%d", a); prints the updated value of a, which is 25.
Try the question first, then check your work.
Examiner trap
Trace how pointer p inside function foo dereferences to the address of a and modifies its value directly.
This Programming in C previous year question is Q34 of the GATE CSE 2025 Set 1 paper. Find more GATE CSE PYQs on Programming in C in Programming and Data Structures, or browse all GATE CSE PYQs.
Free diagnostic
Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Programming in C PYQs now with no account.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
Programming in C has 74 GATE CSE PYQs across 25 papers from 2011 to 2026. 16 of them are 1-mark NAT questions like this one, and GATE CSE 2025 Set 1 has 3.
How GATE tests Programming in CIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.