//call by refernce
#include <iostream.h>
#include <conio.h>
void main()
{
int a, b;
int &refa = a;
int &refb = b;
void swap (int &, int &);
clrscr();
cout << "Enter value a : ";
cin >> a;
cout << "Enter value b : ";
cin >> b;
cout << "Before swaping value : " << endl;
cout << "A = " << a << endl;
cout << "B = " << b << endl;
swap(refa, refb);
cout << "After swaping value :" << endl;
cout << "A = " << a << endl;
cout << "B = " << b << endl;
getch();
}
void swap(int &ref1, int &ref2)
{
int c;
c = ref1;
ref1 = ref2;
ref2 = c;
}
Comments
Post a Comment