Question:


Show Hint

In C, when you pass a pointer to a function, any modification to the value pointed to by the pointer will affect the original variable. Ensure you understand how pointers work when analyzing such programs.
Updated On: Jan 30, 2026
Hide Solution
collegedunia
Verified By Collegedunia

Correct Answer: 25

Solution and Explanation

Let’s analyze the program step by step: 1. Function `foo`: The function `foo` takes two arguments: a pointer `p` and an integer `x`. Inside the function, the value of `x` is assigned to the variable that `p` is pointing to. In this case, `p` points to `a`, so `a` will be updated to the value of `x`, which is 25. 2. In the `main` function:
`a` is initialized to 20, and `b` is initialized to 25.
`z` is a pointer, and it is assigned the address of `a`, so `z` now points to `a`.
`foo(z, b)` is called, which passes `z` (the address of `a`) and `b` (which is 25) to the function.
- Inside `foo`, `z = b` sets the value of `a` to 25 because `z` points to `a`.
3. Output: After the call to `foo`, `a` is updated to 25, and the `printf` statement prints the value of `a`, which is now 25. Thus, the output of the program is 25.
Was this answer helpful?
0
0

Top Questions on Programming in C

View More Questions