Back to Course
Functions

Call by Value and Call by Reference in C

Call by Value

In call by value, a copy of the argument's value is passed to the function. Changes made inside the function do not affect the original variable.

void modify(int x) {
    x = x + 10;
}
int main() {
    int a = 5;
    modify(a);
    printf("%d", a); // 5 (unchanged)
}

Call by Reference

In call by reference, the address of the variable is passed using pointers, so changes inside the function affect the original variable.

void modify(int *x) {
    *x = *x + 10;
}
int main() {
    int a = 5;
    modify(&a);
    printf("%d", a); // 15 (changed)
}

Ready to master real-world C Programming development?

Learn C Programming hands-on with mentor-led, live sessions.

Explore Course