Difficulty: Easy
Correct Answer: reference, pointer
Explanation:
Introduction / Context:How arguments are passed to functions determines whether the callee can change the caller's variables. In C++, three idioms are prevalent: pass by value, pass by reference, and pass by pointer. Understanding their effects on mutability and performance is fundamental to API design and safe coding practices.
Given Data / Assumptions:
Concept / Approach:
Step-by-Step Explanation:
Evaluate each method: value (no external change), reference (allows change), pointer (allows change).Identify the two that enable modification: reference and pointer.Confirm that passing arrays typically passes a pointer to the first element, but semantics depend on how the callee uses it.Verification / Alternative check:
Example: void inc(int& x){++x;} and void incp(int* p){++*p;} both change the caller's variable when invoked correctly.Why Other Options Are Wrong:
Common Pitfalls:
Final Answer:
reference, pointer
Discussion & Comments