C++ Program To Swap Value By Passing Reference | C Programming

C++ Program To Swap Value By Passing Reference

#include<iostream> 
using namespace std; 
#include<iomanip> 
int swap(int &a, int &b) 
{ 
 int temp; 
 temp=a; 
 a=b; 
 b=temp; 
 return 0; 
} 
int main() 
{ 
 int a,b; 
 cout<<"Enter the value of a and b \n"; 
 cin>>a>>b; 
 swap(a,b); 
 cout<<"The swapped value of a is "<<a<<endl<<"The swapped value of b is "<<b; 
}


OUTPUT

Enter the value of a and b
60
90
The swapped value of a is 90
The swapped value of b is 60

Post a Comment

0 Comments