Swap Two Numbers using Call By Value C Program

By | September 17, 2015

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

#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

Swap Two Numbers using Call By Value in C Programming

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.

One thought on “Swap Two Numbers using Call By Value C Program

Let's Discuss