0

Help Don’t understand

Can anyone help explain on why 4 was the answer? https://code.sololearn.com/cMQBlg3YwJXd/?ref=app

15th Nov 2019, 3:00 AM
Elijah
Elijah - avatar
1 Odpowiedź
0
Here evaluation step by step⤵️ • Variable initialization: - Variable x is initialized to 0. - Variable y is assigned the value of --x. Here, --x means decrement the value of x by 1 before assigning it to y, so x becomes -1, and y also becomes -1. • Condition in the if statement: - The condition ++y + 5 is evaluated. Since y is now -1, ++y increments y by 1 making it 0. So, 0 + 5 becomes true or non-zero. • Inside the if block: - The if block executes because the condition is true. - y is multiplied by 5: 0 * 5 = 0 - y is then incremented by 5: 0 + 5 = 5 • Output: - x is still -1, and y is now 5. - When we print x+y, it becomes -1 + 5 = 4. Thanks 😊
14th Apr 2024, 6:37 AM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar