Почему следующая функция называется трижды
Я пытался отладить, но не повезло, я не могу понять, почему второй printf () трижды вызывается приращением (), а первый - дважды, как ожидалось.
#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