Exercise 4-14

Define a macro swap(t,x,y) that interchanges two arguments of type t. (Block structure will help.)

We already know that to swap two integers x and y, we use the following code:

    int z = x;
    x = y;
    y = z;

Replacing int with t and using the macro block structure, we can write swap as follows.

    /* swap:  swap two variables x and y of type t */
    #define swap(t, x, y) \
        t z = x; \
        x = y; \
        y = z;