Write a program to swap the content of two variables using a reference variable.
#include<iostream> using namespace std; void swap_data(int&,int&); int main() { int a = 2, b = 4; cout << "a = " << a << " b = " << b << endl; swap_data(a,b); cout << "a = " << a << " b = " << b << endl; return 0; } void swap_data(int &i,int &j) { int t; t = i; i = j; j = t; }
Output
a = 2 b = 4 a = 4 b = 2