我知道运算符的作用,但是我不理解下面代码中第二个情况为什么会返回1。
#define MIN(a,b) a<b ? a:b
int x = MIN(1,2); //case 1, output is 1
int x = MIN(1,1+1); // case 2
编译器不应该将这种情况(案例2)视为“1<1+1吗?”,我认为应该是“1<1吗?不是的”,执行表达式3,我们得到:b = 1 + 1 = 2。这是因为上面的宏定义中a和b周围没有括号,或者可能是因为我在遵循自己的规则,感到迷失了?请帮忙解决...
另外,你如何解释这种情况:
int x = MIN(1,2) + 1; //should we consider the "1" on the right?
#define MIN(a,b) (((a)<(b)) ? (a):(b))
- J...S