//程序功能实现,计算两个数的最小值
#include
#define MIN(x,y) ((x)<(y)?(x):(y))
int main(int argc, char *argv[])
{
int x=10,y=15;
printf("MIN(%d,%d)=%d\n",x,y,MIN(x,y));
return 0;
}
需要注意的是,宏定义是原样替换,需要保证替换后的准确性,例如,
#define MIN(x,y) (x
#define MIN1(x,y) (x
int main(int argc, char *argv[])
{
int x=10,y=15;
printf("MIN1(%d,%d)=%d\n",x,y,MIN1(x+=2,y));//输出MIN1(24,15)=24
x=10;
printf("MIN2(%d,%d)=%d\n",x,y,MIN2(x+=2,y));//输出MIN2(14,15)=14
return 0;
}