Created
December 8, 2022 08:31
-
-
Save sarmadgulzar/0b162765a855b7eeed36d9ca0fd2784c to your computer and use it in GitHub Desktop.
Swap values without using a third variable
This file contains hidden or 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
| #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