Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Swap Values Without Temporary Variable

DZone's Guide to

Swap Values Without Temporary Variable

·
Free Resource
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:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}