C++ program to swap two numbers using call by value

swap two numbers

This program illustrate the concept to swap two numbers using call by value.Passing arguments in this way, where the function creates copies of argument passed to it, is called call by value.

Program

#include<iostream.h>
#include<conio.h>
void swap(int,int);
void main()
{
clrscr();
int x,y;
cout<<"Enter Value of x = ";
cin>>x;
cout<<"Enter Value of y = ";
cin>>y;
swap(x,y);
getch();
}
void swap(int a,int b)
{
int t;
cout<<"Value of x before swaping = "<<a<<endl;
cout<<"Value of y before swaping = "<<b<<endl;
t=a;
a=b;
b=t;
cout<<"Value of x after swaping = "<<a<<endl;
cout<<"Value of y before swaping = "<<b;
}

OUTPUT:-

swap two numbers

Comment below if you are facing any problem and subscribe to our newsletter for latest update.


Also read

C++ Program to find greatest between three numbers using Functions
C++ program to print 3×3 matrix using class
C++ Program to add two numbers by defining function Outside the class

Summary
C++ program to swap two numbers using call by value
Article Name
C++ program to swap two numbers using call by value
Description
This program illustrate the concept to swap two numbers using functions.The arguments are passed using call by value.
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

Your email address will not be published. Required fields are marked *