Three ways to swap values of the numbers

Common development:

int temp = a;
a = b;
b = temp;

Adding:

a = a + b;
b = a - b;
a = a - b;

By bit XOR:

a=a^b;
b=a^b;
a=a^b;

Note: by bit XOR mode, requiring only an integer; a and b are as indexing arrays, two values can not be the same - or else to a lower target value and b is 0.

Published 55 original articles · won praise 61 · views 20000 +

Guess you like

Origin blog.csdn.net/Agg_bin/article/details/96292963