Prog 5: Write a program to swap two value using reference variable
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int A,B,temp;
cout<<"\n Enter the value of A";
cin>>A;
cout<<"\n Enter the value of B";
cin>>B;
int &P=A;
int &Q=B;
temp=P;
P=Q;
Q=temp;
cout<<"After swaping"<<endl;
int &Q=B;
temp=P;
P=Q;
Q=temp;
cout<<"After swaping"<<endl;
cout<<"A ="<<A<<endl;
cout<<"A ="<<A<<endl;
cout<<"A ="<<A<<endl;
}
Output:
Enter the value
of A
10
Enter the value
of B
20
After swapping A & B
are: A =20
B =10
No comments:
Post a Comment