Over a million developers have joined DZone.

Swap Values Without Temporary Variable

·
The XOR swap algorithm is an inefficient method of swapping two variables. http://en.wikipedia.org/wiki/Xor_swap_algorithm


void XORSwap(void *x, void *y)
{
   *x ^= *y;
   *y ^= *x;
   *x ^= *y;
}
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}