# Pass by Value

> The function gets a copy. Changing the copy leaves the first one alone.

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

## Think of it like

It is like giving a friend a copy of your drawing. They can scribble on it, and yours stays clean.

## Definition

Pass by value means a function gets a copy of each argument. If the function changes its copy, the caller's value stays the same. C, Java and many other languages pass simple values like numbers this way. It keeps functions from changing things by surprise. The cost is copying, which can be slow for very big data.

## Example

A score of 5 is passed to a function that adds 1. Inside it is 6, but back outside the score is still 5.

## Example code

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

int score = 5;
addOne(score);
// score is still 5
```

The function changed its own copy. The caller's score did not move.

## Why it matters

It tells you whether a function can change your data. Guess wrong and a bug hides in a value you thought was safe.

## Common mistake

Expecting a change inside the function to show outside. Return the new value instead.

## Three principles

- **A copy goes in.** The function never sees the original.
- **Original is safe.** Changes stay inside the function.
- **Copying costs.** Big data takes time to copy.

## Related terms

- [Pass by Reference](https://learn.benibix.com/term/development/pass-by-reference)
- [Argument](https://learn.benibix.com/term/development/argument)
- [Parameter](https://learn.benibix.com/term/development/parameter)
- [Function](https://learn.benibix.com/term/development/function)
- [Return Value](https://learn.benibix.com/term/development/return-value)

## 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-value
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.
