swap values without temporary variable
1 2 void XORSwap(void *x, void *y) 3 { 4 *x ^= *y; 5 *y ^= *x; 6 *x ^= *y; 7 }
DZone Snippets > nevadalife > c
12876 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
1 2 void XORSwap(void *x, void *y) 3 { 4 *x ^= *y; 5 *y ^= *x; 6 *x ^= *y; 7 }
1 2 unsigned bit_count(unsigned x) { 3 unsigned n; 4 for (n = 0; x; n++) 5 x &= x-1; 6 return n; 7 }