GateAI
Programming in C

GATE CSE 2025 Set 1 · Q34

NAT1 markEasy

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

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 25

Programming in C

Let us trace the execution of the program step by step:

  1. Inside main(), integer variables a and b are initialized with values 20 and 25, respectively.

  2. The pointer z is assigned the address of a (z = &a), meaning z points to a.

  3. 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.

  4. 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.

  5. After foo() returns, printf("%d", a); prints the updated value of a, which is 25.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

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

Where do you stand for GATE?

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.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Programming in C in GATE CSE

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 C

More from GATE CSE 2025 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2025 Set 1 · Q34 · NAT

#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

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.