Skip to content

Instantly share code, notes, and snippets.

@YuukiARIA
Created April 18, 2014 08:59
Show Gist options
  • Save YuukiARIA/11032739 to your computer and use it in GitHub Desktop.
Save YuukiARIA/11032739 to your computer and use it in GitHub Desktop.
C++ swap
#include <cstdio>
using namespace std;
void swap(int &a, int &b)
{
int t = a;
a = b;
b = t;
}
int main()
{
int a = 1, b = 2;
printf("%d,%d\n", a, b); // ==> 1,2
swap(a, b);
printf("%d,%d\n", a, b); // ==> 2,1
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment