# Pass by Reference

> The function gets a link to the real value. So its changes show outside too.

**Field:** Software Development  
**Category:** Programming Concepts  
**Also known as:** Call by Reference, Passing by Reference

## Think of it like

It is like giving a friend your house key. Whatever they move inside, you will find moved.

## Definition

Pass by reference means a function gets a link to the caller's own variable, not a copy. If the function changes it, the caller sees the change. C++ does this when a parameter is marked with &. It avoids copying big data. But a function can now change things the caller did not expect.

## Example

A score of 5 is passed by reference to a function that adds 1. Back outside, the score now reads 6.

## Example code

```cpp
void addOne(int& n) { n = n + 1; }

int score = 5;
addOne(score);
// score is now 6
```

The & makes n a link to score. Changing n changes score.

## Why it matters

It lets a function update big data without copying it. It is also a common source of surprise changes.

## Common mistake

Thinking all languages work this way. Python and Java do not. A function there can change an object you pass, but it cannot swap your variable for a new one.

## Three principles

- **A link goes in.** The function reaches the original.
- **Changes show.** The caller sees every edit.
- **No copy.** Fast, even for big data.

## Related terms

- [Pass by Value](https://learn.benibix.com/term/development/pass-by-value)
- [Argument](https://learn.benibix.com/term/development/argument)
- [Parameter](https://learn.benibix.com/term/development/parameter)
- [Pointer](https://learn.benibix.com/term/development/pointer)
- [Function](https://learn.benibix.com/term/development/function)
- [Side Effect](https://learn.benibix.com/term/development/side-effect)

## Told apart from

- [Pass by Value vs Pass by Reference](https://learn.benibix.com/compare/pass-by-value-vs-pass-by-reference): With pass by value, a function gets a copy, so your own value stays the same. With pass by reference, it gets a link to your value, so its changes show outside too.

## Taught in

- [Scope and Passing Arguments](https://learn.benibix.com/learn/development-concepts/scope-and-passing-arguments): Programming Basics, 13/18

![Two panels. On the left, pass by value: the score 5 is copied into a function, the copy becomes 6, and the original still reads 5. On the right, pass by reference: the function gets an arrow to the original score box, so when it adds one, the original reads 6.](https://learn.benibix.com/diagrams/dev7-pass-by.svg)

---

Source: https://learn.benibix.com/term/development/pass-by-reference
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
