1、
#include <stdio.h> #define swap(type, a, b) {type tmp = a; a = b; b = tmp;} int main(void) { int x = 5, y = 10; printf("initial value x = %d ", x); printf("initial value y = %d ", y); swap(int, x, y); printf("processed value x = %d ", x); printf("processed value y = %d ", y); return 0; }
2、
#include <stdio.h> #define swap(type, a, b) {type tmp = a; a = b; b = tmp;} int main(void) { int x = 5, y = 10; swap(int, x, y); printf("x = %d ", x); printf("y = %d ", y); double m = 2.44, n = 32.2321; swap(double, m, n); printf("m = %f ", m); printf("n = %f ", n); return 0; }