Short5 marksmediumSolution
Explain the difference between call by value and call by reference in C with suitable code snippets.
C Programming
Nepal's open education portal — School, +2, Diploma, Bachelor & Master in one place
solution · en · Verified by Editorial Board
| Feature | Call by Value | Call by Reference |
|---|---|---|
| Parameter Passing | Passes a copy of the actual argument. | Passes the memory address of the actual argument using pointers. |
| Modification | Changes made in called function do not affect caller variables. | Changes made in called function directly modify caller variables. |
| Memory | Consumes additional memory for parameters. | Memory efficient (operates directly on original memory). |
```c // Call by Value void swapValue(int a, int b) { int temp = a; a = b; b = temp; }
// Call by Reference void swapRef(int a, int b) { int temp = a; a = b; b = temp; } ```