Nepal's open education portal

EduNepalEduNepal
Short5 marksmediumSolution

Explain the difference between call by value and call by reference in C with suitable code snippets.

C Programming

Verified Solution & Step-by-Step Explanation

solution · en · Verified by Editorial Board

Call by Value vs Call by Reference

FeatureCall by ValueCall by Reference
Parameter PassingPasses a copy of the actual argument.Passes the memory address of the actual argument using pointers.
ModificationChanges made in called function do not affect caller variables.Changes made in called function directly modify caller variables.
MemoryConsumes 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; } ```