Quantcast
Channel: User HolyBlackCat - Stack Overflow
Viewing all articles
Browse latest Browse all 1280

Answer by HolyBlackCat for How can I swap two variable's value considering with the memory management and is there any better way to solve this?

$
0
0

(1) is the correct option.

(2) doesn't compile, and I have no idea what was your intent there.

(3) is pointless. Firstly, it can overflow and cause undefined behavior. There's a similar technique called XOR swap, that's not prone to overflows: a ^= b ^= a ^= b;, but it's mostly a clever trick with no practical use. Wikipedia suggests to avoid it for performance reasons.


Viewing all articles
Browse latest Browse all 1280

Trending Articles