Which statement best describes the call-by-value parameter passing mechanism?
Think about whether changes inside the function affect the original variable.
In call-by-value, the function works with a copy of the argument's value. Any changes inside the function do not affect the original variable outside.
In which parameter passing mechanism does the called function directly modify the caller's variable?
Consider which method allows the function to change the original variable.
Call-by-reference passes the variable's address or reference, allowing the function to modify the original variable directly.
Consider the following code snippet in a language supporting call-by-name:
function f(x) { return x + x; }
f(3 + 4)What is the difference in evaluation between call-by-name and call-by-value for the argument 3 + 4?
Think about when the argument expression is evaluated in each mechanism.
Call-by-value evaluates the argument once before the function call, passing the value. Call-by-name delays evaluation until each use inside the function, so 3 + 4 is evaluated twice.
In the call-by-result parameter passing mechanism, what happens to the variable passed as an argument after the function finishes execution?
Consider when the variable's value is copied back to the caller.
Call-by-result copies the value back to the caller's variable only after the function finishes, reflecting the final computed value.
Which of the following statements correctly distinguishes call-by-value-result (copy-in copy-out) from call-by-reference?
Think about when the caller's variable is updated in each mechanism.
Call-by-value-result copies the argument value into the function and copies it back after the function finishes, so changes are not visible during execution. Call-by-reference passes the variable's address, so changes are immediate.