C++ program to swap values of two variables using pass by reference method

CWC
0 Min Read

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;
}
Share This Article
Leave a comment

Leave a Reply

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

English
Exit mobile version