C Pass by Value

Beginner
6 min read
Updated: Nov 2026
1 example

What Is Pass by Value?

C passes everything by value. The function receives a copy of each argument, so changing a parameter does not change the caller's variable. Pointer arguments are also copied, but the copy still points to the original object.

Remember
void bump(int n) { n = n + 1; }  /* changes the copy */

int x = 5;
bump(x);        /* x is still 5 */

Cheat Sheet

Keep these facts handy while you work with Pass by Value in C.

TopicDetail
CopyParameter is a new variable
SafeCaller's data cannot be changed by accident
CostLarge structs are expensive to copy
Need changes?Pass a pointer — see pass by reference

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Pass by Reference.

Example 1 — The caller's variable is unchanged

The function modifies only its own copy.

C
#include <stdio.h>

void add_one(int n) {
    n = n + 1;
    printf("inside:  %d\n", n);
}

int main(void) {
    int x = 5;
    add_one(x);
    printf("outside: %d\n", x);
    return 0;
}

How It Works

  1. n starts as a copy of x (5).
  2. Inside, n becomes 6.
  3. When the function returns, n disappears and x is still 5.

Edge Cases & Pitfalls

Check these before relying on Pass by Value in real programs.

expect

Expecting a swap to work

A swap(int a, int b) function swaps only its copies. Use pointers.

struct

Copying big structs

Passing a large struct by value copies every byte. Pass const struct T * instead.

Key Takeaways

  • Always: C is pass by value.
  • Pointers: the copy still points to the original.
  • Performance: avoid copying big structs.

One line: C passes everything by value.

Frequently Asked Questions

Not as a language feature. You simulate it by passing a pointer, which is itself passed by value but lets the function change the pointed-to object.
Because it received a copy. Pass &variable and dereference the pointer parameter inside the function.
Continue with "C Pass by Reference" next. Pass addresses so a function can modify the caller's variables. The C Functions hub lists every topic in order.

Next: Pass by Reference

Pass addresses so a function can modify the caller's variables.

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful