C++ program to swap values of two variables using pass by reference method
#include
#include
using namespace std;
int main()
{
int a,b;
void swap(int &,int &);
cout<<"Enter two values:"; cin>>a>>b;
cout<<"\nBefor swapping:\na="<<a<<"\tb="<<b;
swap(a,b);
cout<<"\n\nAfter swapping:\na="<<a<<"\tb="<<b;
return 0;
}
void swap(int & x,int & y)
{
int temp;
temp=x;
x=y;
y=temp;
}