Swap two Numbers using Call by Reference
Here, you will get a program code of Swap two Numbers using Call By Reference in c language. I have tried to clear the logic of call by reference 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 Reference in C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | //Swapping two numbers using Call by Reference #include <stdio.h> void swapByRef(int*, int*); void swapByRef(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); swapByRef(&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