Does C use short circuit evaluation even when arguments are function calls?

前端 未结 3 1721
无人共我
无人共我 2021-01-25 03:40

I know that logical operators do short-circuit checking. That is, if there is a statement like A && B && C, then if A is false,

3条回答
  •  庸人自扰
    2021-01-25 04:15

    The Logical and operator will short circuit regardless of what the operands are, if we look at the draft C99 standard section 6.5.13 Logical AND operator paragraph 4 says(emphasis mine):

    Unlike the bitwise binary & operator, the && operator guarantees left-to-right evaluation; there is a sequence point after the evaluation of the first operand. If the first operand compares equal to 0, the second operand is not evaluated.

    Note, the second operand will not be evaluated only if the first is false. Also note it guarantees right to left evaluation and a sequence point after the first evaluation.

提交回复
热议问题