Similar questions 1 more →
Runtime Environments & Parameter Passing


Answer & solution
Answer: x=1, z=100. (no official key was published)
With call by value, evaluate the actual arguments in the caller before entering P: x yields 1, x*y yields 5, and z yields 100. Allocate independent local formals with values (a,b,c)=(1,5,100).
The assignment a:=2 changes only the local a. Next c:=a+b computes 2+5=7 and places it in the local c. Neither assignment targets the caller’s variables, so after return x remains 1, y remains 5, and z remains 100. The main program prints x=1,z=100.
The intermediate c=7 is not the value printed by the program: the print is outside P and names z. Ordinary call by value has no copy-out stage. Adding copy-out would change the parameter mechanism to value-result, which is a different question. Evaluating the expression x*y once at the call is crucial for distinguishing this case from call by name.