现在的位置: 首页 > 综合 > 正文

用宏定义写出swap(x,y)

2018年04月03日 ⁄ 综合 ⁄ 共 165字 ⁄ 字号 评论关闭
#include <stdio.h>

// SWAP(x, y)				交换x,y的值
#define SWAP(x, y) \
	(y) = (x) + (y); \
	(x) = (y) - (x); \
	(y) = (y) - (x);



int main()
{
	int a = 3-2, b = 5*8;
	SWAP(a, b);
	printf("%d, %d\n", a, b);

	return 0;
}

运行结果:

40, 1

抱歉!评论已关闭.