Skip to content

Instantly share code, notes, and snippets.

@lbrito1
Last active September 20, 2015 16:45
Show Gist options
  • Save lbrito1/d8981b0c5d32476aeab9 to your computer and use it in GitHub Desktop.
Save lbrito1/d8981b0c5d32476aeab9 to your computer and use it in GitHub Desktop.
#include <stdio.h>
static inline void exchx(void** a, void** b) { void* p = *a; *a = *b; *b = p; }
int main(void) {
int a = 1;
int b = 2;
int c = 3;
int d = 4;
printf("\nBefore: abcd = %d, %d, %d, %d", a, b, c, d);
exchx((void**)&a,(void**)&b);
printf("\nAfter: abcd = %d, %d, %d, %d\n", a, b, c, d);
}
//Before: abcd = 1, 2, 3, 4
//After: abcd = 2, 1, 2, 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment