C Program To Swap Two Numbers using Call By Value
Learn How To Swap Two Numbers using Call By Value in C Programming Language. Learn C Code To Swap Numbers with Temporary or Third variable and without Third variable. Two variables can be swapped using Functions and without using Functions as well.
This C program swaps two Integers using Call By Value method where the values of the variables are sent to the New Variables and the Old Values are not Swapped.
Also Read: C Program To Swap Two Variables using Call By Reference
C Program To Swap Two Numbers using Call By Value
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 | #include<stdio.h> int swap(int a, int b); int main() { int num1, num2; printf("\nEnter The First Number:\t"); scanf("%d", &num1); printf("\nEnter The Second Number:\t"); scanf("%d", &num2); swap(num1, num2); printf("\nOld Values\n"); printf("\nFirst Number = %d\nSecond Number = %d\n", num1, num2); printf("\n"); return 0; } int swap(int a, int b) { int temp; temp = a; a = b; b = temp; printf("\nNew Values\n"); printf("\nFirst Number = %d\nSecond Number = %d\n", a, b); } |
Also Read: C Program To Swap Two Variables without using Temporary (Third) Variable
Output

If you have any compilation errors or doubts in this C Program To Swap Two Numbers using Call by Value in C Programming Language, let us know about in the Comment Section below.
Want notes on every program for semester 2