About swap function

Sir if we us xor swapping technique in swap function it returns zeroes in some places in array in partition function but returns correct output using normal swapping technique,Why does xor swapping mishandles?

sir link to code is https://ide.codingblocks.com/s/45447
try using xorswap instead of normal swap
i have made both functions

Sir i am not able to reply to your posts and not able to ask more doubts because cb authorities put my account on hold.

Hey bhavya, can you send the link to your code where you are having problem??

https://ide.codingblocks.com/s/45447

Hey Bhavya, in xorswap function don’t take the arguments by reference. Update your xorswap function as this void xorswap(int a,int b)

sir its giving wrong results
xorswap by reference works fine other than the case here

Hey Bhavya, if you don’t pass arguments in xorswap function it is working fine, can you share the problem’s link or exact problem’s name for which it is giving wrong answer.

https://ide.codingblocks.com/s/45447

sir here is the link of my code.
there is a xorswap function and a swap function.
if i use swap function , my quicksort function works fine but if i use xorswap it give wrong answers.
also sir,xorswap is working fine other than in the quicksort function i made here.

sir pls help .
i shared the link to code

Hey Bhavya, in your xorswap function just put an if check if(a!=b) then swap the numbers, it will work fine then, otherwise when two same no. will be compared it will make them zero. You can refer this code snippet given below:

void xorswap(int& a,int& b)  //xor swapping technique
{
	if (a != b)
    {
		a = a ^ b;
		b = a ^ b;
		a = a ^ b;
	}
}

yes sir thanks program is working fine now

sir i checked it now and now know why problem has arised;
its because it was sometimes taking in same element address and stores 0 as xor in that address;
thanks sir a lot