Last active
June 18, 2024 08:05
-
-
Save krishvishal/47e470da10e13e4cd4950d5febe9f157 to your computer and use it in GitHub Desktop.
Swap variables without using temporaries in Julia
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
function swap(a, b) | |
a = xor(a, b) | |
b = xor(a, b) | |
a = xor(a, b) | |
return a, b | |
end | |
a, b = 1, 2 | |
println(a, " ", b) | |
a, b = swap(a, b) | |
println(a, " ", b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment