【发布时间】:2021-11-06 18:48:56
【问题描述】:
无法理解为什么会产生这个输出。请详细说明。
下面的代码给了我想要的输出。喜欢
#include <stdio.h>
#define product(p,q) p*q
int main()
{
printf("%d",product(5,3));
return 0;
}
输出:
15
但下面代码中的相同逻辑和宏给了我如下输出。
#include <stdio.h>
#define product(p,q) p*q
int main()
{
int x=3,y=4;
printf("%d",product(x+2,y-1)); // x+2=5 and y-1=3
return 0;
}
输出:
10
【问题讨论】:
-
括号问题:3+2*4-1 = 10。见gcc.gnu.org/onlinedocs/cpp/…