Call by Value in C Programming (Complete Guide with Examples)
This tutorial explains call by value in C, a method of passing arguments to functions. It shows how a copy of the variable is passed to the function, leaving the original variable unchanged. Examples demonstrate its behavior and use in modular programming.
1. What is Call by Value
Call by value is a method of passing arguments to a function where the function receives a copy of the actual parameter.
- Changes made inside the function do not affect the original variable.
- Default method of argument passing in C.
2. Syntax
Function Call:
3. Example: Swapping Numbers Using Call by Value
Sample Output:
Observation:
The values of x and y in main() remain unchanged because only copies were passed.
4. Key Points to Remember
- Call by value passes a copy of the variable.
- Original variable in the calling function remains unchanged.
- Simple and safe to use for small data types like
int,float,char. - To modify the original variable, use call by reference (pointers).