diff --git a/k&r/04-funcs-and-prog-struct/04-14.c b/k&r/04-funcs-and-prog-struct/04-14.c new file mode 100644 index 0000000..82b677d --- /dev/null +++ b/k&r/04-funcs-and-prog-struct/04-14.c @@ -0,0 +1,18 @@ +#include + +#define swap(T, x, y) \ + do { \ + T temp; \ + temp = x, x = y, y = temp; \ + } while (0) + +/* swap x and y */ +int main() +{ + int x, y; + x = -1, y = 1; + printf("x = %d, y = %d\n", x, y); + swap(int, x, y); + printf("x = %d, y = %d\n", x, y); + return 0; +}