#define SWAP(a,b) {int t;t=a;a=b;b=t;}……求详解!void main(){int x=1,y=2;SWAP(x,y);printf("x=%d,y=%d\n",x,y);}

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 13:29:26

#define SWAP(a,b) {int t;t=a;a=b;b=t;}……求详解!void main(){int x=1,y=2;SWAP(x,y);printf("x=%d,y=%d\n",x,y);}
#define SWAP(a,b) {int t;t=a;a=b;b=t;}……求详解!
void main()
{
int x=1,y=2;
SWAP(x,y);
printf("x=%d,y=%d\n",x,y);
}

#define SWAP(a,b) {int t;t=a;a=b;b=t;}……求详解!void main(){int x=1,y=2;SWAP(x,y);printf("x=%d,y=%d\n",x,y);}
#define SWAP(a,b) {int t;t=a;a=b;b=t;}是编译预处理命令中的宏定义,只要出现SWAP(a,b)就用复合语句{int t;t=a;a=b;b=t;}来代替,
对应你的main:SWAP(x,y)就被代替为 {int t;t=x;x=y;y=t;}
也就变成:
void main(){int x=1,y=2;{
int t;
t=x;
x=y;
y=t;
} printf("x=%d,y=%d\n",x,y);}
输出x=2,y=1实现将两个变量值交换的功能.