Created
April 18, 2014 08:59
-
-
Save YuukiARIA/11032739 to your computer and use it in GitHub Desktop.
C++ swap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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