Mega Code Archive
Categories
/
C++ Tutorial
/
Data Types
Use reference to swap value
#include
void Swap(int& x,int& y); int main(void) { int n1 = 1, n2 = 2; Swap(n1,n2); cout << n1 << " " << n2 << endl; } void Swap(int& x,int& y) { int t = x; x = y; y = t; } 2 1