Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Exercise 47

C Exercise 47

100 Classic C Language Examples 100 Classic C Language Examples

**Problem:** Practice the macro #define command 2.

**Analysis:** None.

Program source code:



//  Created by www.runoob.com on 15/11/9.

//  Copyright © 2015 Runoob Tutorial. All rights reserved.

//



#include

#define exchange(a,b) { int t;t=a;a=b;b=t;}//Note: put it on one line

int main()

{

    int x=10;

    int y=20;

    printf("x=%d; y=%d\n",x,y);

    exchange(x,y);

    printf("x=%d; y=%d\n",x,y);

    return 0;

}

The output of the above example is:



x=10; y=20

x=20; y=10

100 Classic C Language Examples 100 Classic C Language Examples