#include <stdio.h>
#define SQUARE(X) X*X
#define PR(X) printf("The result is %d.\n",X)
int main(void)
{
int x=4;
int z;
z=SQUARE(x);
PR(z);
z=SQUARE(2);
PR(z);
PR(SQUARE(x+2));
PR(SQUARE((x+2)));
PR(100/SQUARE(2));
PR(100/(SQUARE(2)));
PR(SQUARE(++x));
PR(SQUARE((++x)));
getch();
return 0;
}
|
运行结果如下:
The result is 16.
The result is 4.
The result is 14.
The result is 36.
The result is 100.
The result is 25.
The result is 30.
The result is 56.
|
简单比对一下结果:
PR(SQUARE(x+2));为4+2*4+2=14
PR(SQUARE((x+2)));为(4+2)*(4+2)=36
PR(100/SQUARE(2));为100/2*2=100
PR(100/(SQUARE(2)));为100/(2*2)=25
PR(SQUARE(++x));为++x*++x=(4+1)*(5+1)=30
PR(SQUARE((++x)));(++x)*(++x)=(6+1)*(7+1)=56
宏运算首先要将宏表达式展开,然后再代入,展开表达式不要随便带括号,要考虑运算优先级
阅读(282) | 评论(0) | 转发(0) |