Skip to content

Instantly share code, notes, and snippets.



Created Oct 21, 2013
What would you like to do?
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