Four ways to exchange the values of 2 variables

1. Use the third variable: c=a, a=b, b=c
2. Use 4 variables, give the values ​​of a and b to c and d respectively, and then exchange
3. Just two variables, use Addition/subtraction/division
Insert picture description here
4, or two variables, use the exclusive OR operation (binary, the same is 0, the difference is 1, that is, the same false but different true)
Insert picture description here

Guess you like

Origin blog.csdn.net/ExceptionCoder/article/details/107089075