Skip to content

Instantly share code, notes, and snippets.

@sarmadgulzar
Created December 8, 2022 08:31
Show Gist options
  • Select an option

  • Save sarmadgulzar/0b162765a855b7eeed36d9ca0fd2784c to your computer and use it in GitHub Desktop.

Select an option

Save sarmadgulzar/0b162765a855b7eeed36d9ca0fd2784c to your computer and use it in GitHub Desktop.
Swap values without using a third variable
#include <iostream>
int main() {
int a = 7;
int b = 5;
std::cout << "Before: a=" << a << ", b=" << b << "\n";
a += b;
b = a - b;
a -= b;
std::cout << "After: a=" << a << ", b=" << b << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment