Does the compiler continue evaluating an expression where all must be true if the first is false?

后端 未结 6 1932
误落风尘
误落风尘 2020-12-11 21:41

I\'m sure this question has probably been answered before, so I apologize, but I wasn\'t able to find the proper search terms to find the answer.

Given the following

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-11 22:14

    No. Both && and || are evaluated by short-circuit evaluation. This means that a && b returns false if a is false and a || b returns true if a is true and it will not evaluate b in either of these cases.

    If for some reason you do not want short-circuit evaluation you can use the bitwise operators & and |.

提交回复
热议问题