C Programming: Understanding Logical Operators and Short-Circuit Evaluation
The output of the code will be:
x=1 y=0
x=2 y=0
\nExplanation:\
- In the first line, the expression
!x||y++is evaluated.xis 1, so!xis false (0). Since the OR operator (||) short-circuits, they++part is not executed. So,yremains 0. Therefore, the first print statement outputsx=1 y=0.\ - In the second line, the expression
!y&&++xis evaluated.yis 0, so!yis true (1). But, since the AND operator (&&) short-circuits, the++xpart is not executed. So,xremains 1. Therefore, the second print statement outputsx=1 y=0.
原文地址: https://www.cveoy.top/t/topic/p3Kw 著作权归作者所有。请勿转载和采集!