Created
October 21, 2013 06:06
-
-
Save snj/7079322 to your computer and use it in GitHub Desktop.
swap a and b without tmp var
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 <iostream> | |
void swap(int& a, int& b){ | |
b ^= a; a ^= b; b ^= a; | |
} | |
int main(){ | |
int a = 1, b = 2; | |
swap(a, b); | |
std::cout << a << " " << b << std::endl; | |
return 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment