C Programming: Understanding the Output of Multiple Assignment and Comparison Expressions
The output of this program is:
3,1,1,1
Explanation:
- The expression 'a = b = c' assigns the value of 'c' to both 'b' and 'a', so 'a' and 'b' become 3. This expression returns the value of 'c', which is 3.
- The expression 'a=b == c' first evaluates 'b == c', which is false (0), and then assigns the result to 'a' and 'b'. So 'a' and 'b' become 0. This expression returns the value of 'b == c', which is false (0).
- The expression 'a == (b = c)' assigns the value of 'c' to 'b', so 'b' becomes 3. Then it compares 'a' (which is still 3) to the value of 'b', which is 3. The result is true (1). This expression returns the value of the comparison, which is true (1).
- The expression 'a == (b == c)' compares 'b' to 'c', which is true (1), and then compares 'a' to the result of the previous comparison, which is also true (1). The result is true (1). This expression returns the value of the comparison, which is true (1).
原文地址: http://www.cveoy.top/t/topic/oHKp 著作权归作者所有。请勿转载和采集!