Program in C++ to swap two number using call by reference
#include<iostream> #include<conio.h> using namespace std; void swap(int &,int &); int main() { int a,b; cout<<"Enter two numbers:-"; cin>>a>>b; cout<<"Before swapping value of a ="<<a<<" and value of b ="<<b; swap(a,b); cout<<"\nAfter swapping value of a ="<<a<<" and value of b ="<<b; getch(); return 0; } void swap(int &x,int &y) { int temp=x; x=y; y=temp; }Output:-
0 Comments