Recall & Review
beginner
What is pass by value in parameter passing?
Pass by value means the function receives a copy of the argument's value. Changes inside the function do not affect the original variable.
Click to reveal answer
beginner
Explain pass by reference.
Pass by reference means the function receives a reference (or address) to the original variable. Changes inside the function affect the original variable.
Click to reveal answer
intermediate
What is the difference between pass by value and pass by reference?
Pass by value sends a copy of data, so changes don't affect the original. Pass by reference sends the actual location, so changes affect the original variable.
Click to reveal answer
intermediate
What does pass by value-result mean?
Pass by value-result copies the argument's value to the function (like pass by value) and then copies it back to the original variable after the function finishes.
Click to reveal answer
advanced
Describe pass by name parameter passing.
Pass by name delays evaluation of the argument until it is used inside the function, substituting the argument expression directly. It behaves like textual substitution.
Click to reveal answer
Which parameter passing mechanism allows the function to modify the caller's variable directly?
✗ Incorrect
Pass by reference passes the actual address, so changes inside the function affect the original variable.
In which parameter passing method is the argument evaluated only when used inside the function?
✗ Incorrect
Pass by name delays evaluation until the argument is used, substituting the expression directly.
What happens to the original variable in pass by value-result after the function finishes?
✗ Incorrect
Pass by value-result copies back the local changes to the original variable after the function ends.
Which parameter passing mechanism is safest to avoid unintended side effects?
✗ Incorrect
Pass by value uses copies, so the original data cannot be changed by the function.
Which mechanism can cause unexpected behavior due to multiple evaluations of the argument?
✗ Incorrect
Pass by name substitutes the argument expression directly, so if used multiple times, it evaluates multiple times.
Explain the main differences between pass by value and pass by reference with examples.
Think about whether the function can change the caller's variable.
You got /4 concepts.
Describe pass by value-result and pass by name, and discuss when each might be useful.
Consider copying values vs delaying evaluation.
You got /4 concepts.