Introduction / Context:
Understanding how function arguments are passed is vital to predict whether a callee can modify a caller's data. C++ supports three common styles: pass-by-value, pass-by-reference, and pass-by-pointer. This question focuses on the style where only the data's current content is copied into the function, leaving the caller's original variable unchanged.
Given Data / Assumptions:
- The function receives either a copy of the value, a reference (alias), or a pointer (address).
- No special qualifiers like const are required to understand the basic distinction.
- Side effects on parameters are a key concern in API design and debugging.
Concept / Approach:
- By value: The callee gets its own copy; modifications affect only that copy.
- By reference: The callee receives an alias to the original, allowing direct modification.
- By pointer: The callee receives an address and can modify the pointed-to object via dereferencing.
Step-by-Step Solution:
Identify which method supplies only the data's contents, not its identity/location → pass-by-value.Confirm that changes in the callee do not propagate back to the caller's variable.Hence the blank is correctly filled by 'by value'.
Verification / Alternative check:
Example: void inc(int x){ x++; } int a=5; inc(a); a remains 5 after the call because x is a copy.
Why Other Options Are Wrong:
- by reference: Passes an alias; the callee can change the caller's variable.
- globally / locally: Not parameter-passing mechanisms; they describe scope.
- None of the above: Incorrect because ”by value” is the standard term.
Common Pitfalls:
- Confusing pass-by-value with returning values by copy; these are separate operations.
- Assuming objects are always cheap to copy; use references or move semantics when appropriate.
Final Answer:
by value
Discussion & Comments