Comments on: Swap two variables using XOR https://betterexplained.com/articles/swap-two-variables-using-xor/ Math lessons that click Wed, 01 Mar 2023 23:28:34 +0000 hourly 1 By: Paulami https://betterexplained.com/articles/swap-two-variables-using-xor/#comment-334359 Wed, 25 Jan 2017 10:30:41 +0000 http://betterexplained.com/articles/swap-two-variables-using-xor/#comment-334359 In reply to Anonymous.

Exactly, that’s what I am confused about too. Swapping the pointers is not same as swapping the value at pointed address.

]]>
By: Komal https://betterexplained.com/articles/swap-two-variables-using-xor/#comment-334199 Thu, 05 Jan 2017 16:52:29 +0000 http://betterexplained.com/articles/swap-two-variables-using-xor/#comment-334199 I guess there can be a single line expression which will be much quicker. If i and j are two variables, then the expression for swapping their values will be
i=i+j-(i+j);

]]>
By: Akshay https://betterexplained.com/articles/swap-two-variables-using-xor/#comment-333649 Mon, 19 Sep 2016 12:01:27 +0000 http://betterexplained.com/articles/swap-two-variables-using-xor/#comment-333649 Well i found one more way to do the same

a=2,b=5;
a=(a+b)-(b=a);

]]>
By: Dickie https://betterexplained.com/articles/swap-two-variables-using-xor/#comment-333081 Wed, 29 Jun 2016 09:21:22 +0000 http://betterexplained.com/articles/swap-two-variables-using-xor/#comment-333081 In reply to Kalid.

If x and y are pointers to the same value, then you’re only ‘swapping’ one thing, which is nonsensical?? It’s like say I’m going to swap 1.

]]>