Learn about call by value & call by reference

Differences between call by value and call by reference There are call by value and call by reference methods when passing arguments to a function. Let’s learn the differences between the two methods. Call by value A method that passes only the value when passing an argument to a function Even if the value of the argument is changed within the function, the value of the calling side is not changed. Usually used when passing a variable 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include <stdio.h> void swap(int a, int b) { int temp = a; a = b; b = temp; } int main() { int a = 10, b = 20; swap(a, b); printf("a: %d, b: %d", a, b); return 0; } Execution result: ...

May 16, 2024 · 2 min · 366 words · In-Jun Hwang