Skip to content

Instantly share code, notes, and snippets.

@mruv
Created March 20, 2019 21:39
Show Gist options
  • Save mruv/e9662e15147020f5a12eca1a546c2607 to your computer and use it in GitHub Desktop.
Save mruv/e9662e15147020f5a12eca1a546c2607 to your computer and use it in GitHub Desktop.
Swap 2 numbers without using an extra temporary variable.
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