Solving Complex Situations Only Found in Books #136
monicfenga
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
https://share.bito.ai/static/share?aid=8b843bd8-a2f2-4c86-9580-aec747384278
Question .
Determine the value of
int l=(++i!=(++j==k++) )
whenijk
is 0.Answer :
In the case where the initial values of ijk are all 0, according to the given expression int l=(++i!=(++j==k++)), we can calculate it step by step:
First, ++i means first add 1 to the value of i and then assign the result to l. In this case, the value of i will be 1 and the value of l will be 1 as well.
Next, ++j means add 1 to j and compare it to k. Since k is still 0, the result will be 1. Since the value of k is still 0, the value of j becomes 1 and the comparison is true (1 == 0 returns false).
Finally, k++ means first assign the value of k to l, and then add 1 to the value of k. Since the value of k is 0, the value of l will still be 0, and the value of k will be 1.
In summary, the expression int l=(++i!=(++j==k++)) results in 1 when the initial values of i, j, and k are all 0.
Beta Was this translation helpful? Give feedback.
All reactions