Similar questions 5 more →
Pointers & Memory

Answer & solution
Official answer: 25
Approach: Distinguish copying an argument from modifying the object that a copied pointer designates.
Initially a contains 20 and b contains 25. The assignment z=&a makes z hold the address of a. On calling foo(z,b), the parameter p receives a copy of that same address, while x receives the value 25.
Inside foo, the expression *p is the integer object at p’s address, which is main’s a. Therefore *p=x stores 25 into a. Returning from foo discards its local parameter objects but does not undo the write to a.
The subsequent printf of a prints 25. C still passes arguments by value: p itself is copied, but the copied address can be dereferenced to change an object owned by the caller. If the function had assigned only p or x, that would be a different operation; the dereferencing assignment is decisive.