Created
March 20, 2019 21:39
-
-
Save mruv/e9662e15147020f5a12eca1a546c2607 to your computer and use it in GitHub Desktop.
Swap 2 numbers without using an extra temporary variable.
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
void swap_without_temp(int *x, int *y) { | |
*x = *x + *y; | |
*y = *x - *y; | |
*x = *x - *y; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment