Question about parameter passing modes in programming What i
Question about parameter passing modes in programming:
What is the value printed by the following pseudo-code program for each of the four parameter passing modes call-by-value, call-by-reference, call-by-value/result, and call-by-name? That is, for each of the four parameter passing modes assume that both the x and y parameters use that mode. Show how each program is evaluated in that mode and show the final value printed:Solution
call by value: 2
call by value-result: 3
call by reference: 3
call by name: 2
In call by value, original value is not modified.
In call by reference, original value is modified because we pass reference (address).
Note that when using call by reference, a and x are aliased.
Call-by-name similar to call-by-reference in that you can change the value of the passed in parameter. It differs from call-by-reference in that the parameter is not evaluated before the procedure is called but is instead evaluated lazily. That is, it is evaluated when and only when the parameter is actually used.
