Swap 2 numbers using Call by Value
Here, you will get a program code to swap two numbers using call by value in c programming. I have tried to clear the logic of call by value in a simple way. If you still have any problem then comment me. I will try to reply soon.
Swap two Numbers using Call by Value in C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | //Swapping two numbers using Call by Value #include <stdio.h> void swapByVal(int, int); void swapByVal(int i, int j) { int temp; temp = i; i = j; j = temp; printf("\nNumber After Swapping in swap function \na = %d\nb = %d\n", i, j); } int main() { int a = 10, b = 20; printf("Numbers Before Swapping in main \na = %d\nb = %d\n", a, b); swapByVal(a, b); printf("Numbers After Swapping in main \na = %d\nb = %d\n", a, b); return 0; } |
Output
Check out our other C programming Examples