Skip to content

Instantly share code, notes, and snippets.

@arunenigma
Created March 9, 2013 17:37
Show Gist options
  • Select an option

  • Save arunenigma/5124964 to your computer and use it in GitHub Desktop.

Select an option

Save arunenigma/5124964 to your computer and use it in GitHub Desktop.
Swapping two numbers using Reference Parameters in C++
#include <iostream>
using namespace std;
void swap(int& a, int& b) {
a = a-b;
b = b+a;
a = b-a;
}
int main() {
int a = 10;
int b = 20;
swap(a,b);
cout << "a = " << a << endl;
cout << "b = " << b << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment