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
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)
Four ways to exchange the values of 2 variables
Guess you like
Origin blog.csdn.net/ExceptionCoder/article/details/107089075
Recommended
Ranking