- #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 program is __________. (Answer in integer)
GATE CSE 2025Programming in C › Pointers, Arrays & StringsVerified
25
Trace the C program: z is assigned the address of a, then foo receives that address and the integer value b. Inside foo, the pointer dereference writes b's value into a, so the printf sees the updated value of a.
The function foo modifies the variable a through the pointer z, setting it to the value of b (25). Therefore the output is 25.
Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.