C Programming Function Parameters: Pass by Value

Last modified by Microchip on 2023/11/09 09:06

Parameters passed to a function are passed by value. Values passed to a function are copied into the local parameter variables. The original variable that is passed to a function cannot be modified by the function since only a copy of its value was passed.

1 int a, b, c;
2 int foo(int x, int y);
3  
4 int main(void)
5 {
6   a = 5;
7   b = 10;
8   c = foo(a, b);
9 }
10  int foo(int x, int y)
11 {
12   x = x + (++y);
13   return x;
14 }

The value of a is copied into x.
The value of b is copied into y.
The function does not change the value of a or b.