我曾尝试调试但没有运气,我不明白为什么第二个 printf() 调用了 increment() 三次,但第一个调用了两次。
#include <stdio.h>
#define MAX(a, b) ( (a) > (b) ? (a) : (b) )
int increment(){
static int i = 42;
i += 5;
printf("increment returns %d\n", i); // 47, 52, 57
return i;
}
int main( int argc, char ** argv ) {
int x = 50;
// parameters compute from right to left side
printf("max of %d and %d is %d\n",
x, //3rd: 50
increment(), //2nd: 52
MAX(x, increment()) //1st: 50,47 -> 50
);
printf("max of %d and %d is %d\n",
x, //3rd: 50
increment(), //2nd: 62
MAX(x, increment()) //1st: 50,57 -> 57
);
return 0;
}
结果
increment returns 47
increment returns 52
max of 50 and 52 is 50
increment returns 57
increment returns 62
increment returns 67
max of 50 and 67 is 62