How to preform Swap using CALL BY VALUE fucntion in c c++

First get the input from the user then using call by value function pass the value with three variable we performing swap process in object oriented programming .
Source code call by value swap programming algorithm in c c++
#include<iostream.h>
#include<conio.h>
void swap(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
cout<<"\n The value of a and b in swap fun is\t "<<x<<"\t"<<y;
}
void main()
{
int a,b;
clrscr();
cout<<"\n Enter the value of a and b:\n";
cin>>a>>b;
cout<<"\n The value of a and b before the swap fun is:\t"<<a<<"\t"<<b;
swap(a,b);
cout<<"\n\n The value of a and b after the swap fun is:\t"<<a<<"\t"<<b;
getch();
}
OUTPUT swap fucniton call by value in c++ programming
Enter the value of a and b:
7
2
The value of a and b before the swap fun is: 7 2
The value of a and b in swap fun is: 2 7
The value of a and b after the swap fun is: 7

Related post