Why the following function is called thrice

后端 未结 6 1270
轻奢々
轻奢々 2021-01-20 10:45

I had tried to debug but no luck I can\'t understand why the second printf() is call increment() thrice but the first one call twice as expected.

#include &l         


        
6条回答
  •  逝去的感伤
    2021-01-20 11:33

    ( (a) > (b) ? (a) : (b) )

    In this statement, if b stands for a function, it will be called just once if (a > b) is true, but twice if (a > b) is false: one to give parameters for the comparison(b in "(a) > (b)"), the other to return a value for the whole statement(b in the latter part of the macro).

    In your case, there's an extra call of "b"(increment) to provide the second integer parameter in each test.

    Altogether, its twice and thrice.

提交回复
热议问题