#include <stdio.h> void foo(int *p, int x) { *p = x; } int main() { int *z;…
2025
#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)
Attempted by 172 students.
Show answer & explanation
Correct answer: 25
Answer: 25
Explanation:
The pointer z is assigned the address of a, so z points to the variable a.
The function is called with p pointing to a and x equal to 25; inside the function, *p = x stores 25 into the location pointed to by p (which is a).
After the function returns, a has been updated to 25, so printf prints 25.
Note: There is no undefined behavior here because z is assigned the address of a before it is used.
A video solution is available for this question — log in and enroll to watch it.