Created
October 24, 2010 00:31
-
-
Save javiertoledo/642894 to your computer and use it in GitHub Desktop.
Swap variable values without temp variables
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
/*Initializations*/ | |
int a,b; | |
a=1; | |
b=2; | |
/*The swap code*/ | |
a^=b^=a^=b; | |
/*That's all! Your variables swapped magically*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment