Evaluation of the following expression

后端 未结 3 1409
别跟我提以往
别跟我提以往 2021-01-26 03:25

The following code snippet:

int i=-3,j=2,k=0,m;

m=++i && ++j || ++k;

can be evaluated using two concepts,I believe:

1.Since ++

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-26 04:25

    The && and || operators force left-to-right evaluation. So i++ is evaluated first. If the result of the expression is not 0, then the expression j++ is evaluated. If the result of i++ && j++ is not 1, then k++ is evaluated.

    The && and || operators both introduce sequence points, so the side effects of the ++ operators are applied before the next expression is evaluated. Note that this is not true in general; in most circumstances, the order in which expressions are evaluated and the order in which side effects are applied is unspecified.

提交回复
热议问题