reference to value c++ code example
Example 1: reference function in c++
void swap(int &x, int &y) {
int temp;
temp = x;
x = y;
y = temp;
return;
}
Example 2: reference function in c++
#include <iostream>
using namespace std;
void swap(int &x, int &y);
int main () {
int a = 100;
int b = 200;
cout << "Before swap, value of a :" << a << endl;
cout << "Before swap, value of b :" << b << endl;
swap(a, b);
cout << "After swap, value of a :" << a << endl;
cout << "After swap, value of b :" << b << endl;
return 0;
}