Home > Back-end >  The swap () function, look not to understand ah
The swap () function, look not to understand ah

Time:12-11

 # include & lt; stdio.h> 

Void swap (int * x, int * y)

{
* x=((* x) ^ (*) y);
X * y=((*) ^ (*) y);
* x=((* x) ^ (*) y);
}

Int main ()
{
int a,b;
A=2; B=3;
Swap (& amp; A, & amp; B);
Printf (" % d, % d ", a, b);
}

X=2 ^ 3;
Y=8 ^ 3;
X=8 ^ 512;
Therefore, the value exchange?

CodePudding user response:

^ not power function, this is the bitwise xor in c + +, 0, same different 1
X=2, y=3
X=2 ^ 3=1
Y=1 ^ 3=2
X=1 ^ 2=3

The end result is exchanged,

CodePudding user response:

reference 1st floor Minikinfish response:
^ not power function, this is the bitwise xor in c + +, 0, same different 1
X=2, y=3
X=2 ^ 3=1
Y=1 ^ 3=2
X=1 ^ 2=3

Exchange of the outcome,

Well, I didn't respond to come over, this is the bitwise xor
  • Related