Страницы

Translate

четверг, 29 августа 2013 г.

Exercise 4.14. Define a macro swap(t,x,y) that interchanges two arguments of type t.

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

/* swap(t, x, y) */
#include <stdio.h>

#define SWAP(t, x, y) {t tmp;\
                        tmp = y;\
                        y = x;\
                        x = tmp;}

int main()
{
    int a, b;
    
    a = 25;
    b = 1;
    SWAP(int, a, b);
    printf("a - %d\nb - %d\n", a, b);
    return 0;
}

Result:


Комментариев нет:

Отправить комментарий