1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| #include <stdio.h>;
#define swap_m(x, y, t) ((t)=(x),(x)=(y),(y)=(t))
void swap(int *x, int *y);
int main() { int a = 10; int b = 1; int temp; swap(&a, &b); printf("a=%d, b=%d\n", a, b); swap_m(a, b, temp); printf("a=%d, b=%d\n", a, b); return 0; }
void swap(int *x, int *y) { int tmp; tmp = *x; *x = *y; *y = tmp; }
|