🧩Pass by Reference
Also known as Call by Reference, Passing by Reference
The function gets a link to the real value. So its changes show outside too.
Think of it like
It is like giving a friend your house key. Whatever they move inside, you will find moved.
Example
Why it matters
It lets a function update big data without copying it. It is also a common source of surprise changes.
Definition
Example code
cpp
void addOne(int& n) { n = n + 1; }
int score = 5;
addOne(score);
// score is now 6Common mistake
Key takeaways
- 1A link goes in. The function reaches the original.
- 2Changes show. The caller sees every edit.
- 3No copy. Fast, even for big data.