Syntax
void increment(int& value)
{
++value;
}
int count { 4 };
increment(count);
// count is now 5
The parameter refers directly to the caller’s object. Changes made through the reference affect that object.
When to use it
- The function must modify the caller’s object
- The object is required and cannot be null
- Copying would be unnecessary