#include <stdio.h>
#define test(x) x*x
#define test2(x) x
int main(void) {
int x=5;
printf("%d %d %d %d %d %d",test2(x), test2(x-2), test(x), test(x-2),4*(test(x-3)),4*test(x-3));
return 0;
}
输出如下:
5 3 25 -7 -52 2
很好理解前 3 个,但为什么 test(x-2) 时为 -7,最后 2 个……
最佳答案
编译器预处理步骤之后,您的 printf 变为
printf("%d %d %d %d %d %d",x, x-2, x*x, x-2*x-2,4*(x-3*x-3),4*x-3*x-3);
x-2*x-2 计算为: x-2*x-2 -> x-(2*x)-2
5-10-2
=-7
ie * 优先于 -
关于C#定义奇怪的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43906246/