
Correct : 25
Explanation:
Let's trace the execution of the program line by line:
1. Variable Initialization inside main():
• int a = 20, b = 25; allocates memory for two integer variables, initializing a to 20 and b to 25.
• int *z; declares an integer pointer z.
• z = &a; stores the memory address of variable a inside pointer z. This means z points directly to a.
2. Function Call: foo(z, b);
The program passes two arguments to the function foo:
• The pointer z (which contains the address of a) is passed by value into the local pointer parameter int *p. Therefore, inside foo, p also points to a.
• The value of b (which is 25) is passed into the local integer parameter int x.
3. Execution inside foo():
• *p = x; dereferences the pointer p.
• Because p holds the address of a, modifying *p directly alters the value stored in variable a back in the main function.
• The statement assigns the value of x (25) to a. Thus, the value of a becomes 25.
4. Print Statement inside main():
• After foo(z, b) finishes executing, control returns to main.
• printf("%d", a); prints the current value of a, which has been updated to 25.
Similar Questions
Total Unique Visitors