What is the difference between pass by value and pass by reference?
Show answer and explanation
A non-reference parameter is a separate object initialized from the argument, so modifying it does not modify the caller's object; copying or moving it may have a cost. A reference parameter binds to the caller's object: a non-const reference can modify it, while const T& provides read-only access and often avoids a copy. Choose by contract first—small value types are often best passed by value, and a reference is not automatically faster in every case.
A non-reference parameter is a separate object initialized from the argument, so modifying it does not modify the caller's object; copying or moving it may have a cost. A reference parameter binds to the caller's object: a non-const reference can modify it, while const T& provides read-only access and often avoids a copy. Choose by contract first—small value types are often best passed by value, and a reference is not automatically faster in every case.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.