C Programming: Understanding Logical Operators and Increment Operators
The output of the code is:
x=1 y=0
x=2 y = 0\
Explanation:\
- In the first line, the expression
!x || y++is evaluated. The!xreturns 0 (false) since x is 1, so they++part is not executed. Therefore, the value of x and y remain unchanged.\ - In the second line, the expression
!y && ++xis evaluated. The!yreturns 1 (true) since y is 0, so the++xpart is executed and x becomes 2. Therefore, x is incremented and y remains unchanged.
原文地址: https://www.cveoy.top/t/topic/p3Lf 著作权归作者所有。请勿转载和采集!