Skip to content

Instantly share code, notes, and snippets.

@snj
Created October 21, 2013 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snj/7079322 to your computer and use it in GitHub Desktop.
Save snj/7079322 to your computer and use it in GitHub Desktop.
swap a and b without tmp var
#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