C++ program to swap two integers values and display the values before and after swapping using call by reference
#include<iostream>
using namespace std;
void swap(int &x, int &y)
{
int temp;
temp = x;
x = y;
y = temp;
}
int main()
{
int a, b;
cout<<"Enter the value of a: "; cin>>a;
cout<<"Enter the value of b: "; cin>>b;
cout<<endl<<"Before swapping: ";
cout<<"a= "<<a<<" and b= "<<b;
swap(a, b);
cout<<endl<<"After swapping: ";
cout<<"a= "<<a<<" and b= "<<b;
}
OUTPUT: Enter the value of a: 10 Enter the value of b: 20 Before swapping: a= 10 and b= 20 After swapping: a= 20 and b= 10


