current position:Home>Why output this? Don't you understand?

Why output this? Don't you understand?

2022-01-26 22:00:40 CSDN Q & A

img




Refer to the answer 1:

Layer 1 cycle :x -= 2 Equivalent to x = x - 2, So the output 1, then while Inside !(--x) As the result of the 1, Go on to the next cycle ( Now x become 0);
The second cycle :x -= 2 Equivalent to x = x - 2, So the output -2 , then while Inside !(--x) As the result of the 0, End of cycle ;




Refer to the answer 2:



Refer to the answer 3:

Don't look at the short code , This is about 3 A knowledge
1.do,while In circulation , Execute first do, To determine .
2.--x, Execute first --, Then take
3.int Type conversion bool In the implicit conversion of type ,0=false, Not 0=true
Okay , First cycle ,x-=2, here x=1, Output 1, then --x,x become 0,0 be equal to false, Reverse becomes true, So it goes into the second cycle
The second cycle ,x become -2, Output -2,-2 turn bool yes true, Reverse transformation false, If the condition is not satisfied, jump out of the loop




Refer to the answer 4:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201262200379926.html

Random recommended