C language pointer values of the two switching positions

Value stored at location x and y variables pointer exchange pointed stored, you do not need to be a third position for storing temporary variables. This way is not a performance advantage.

void replace(int *x, int *y) {
    *y = *x ^ *y;
    *x = *x ^ *y;
    *y = *x ^ *y;
}

 

Guess you like

Origin www.cnblogs.com/frisk/p/11617402.html