+ 1

help me

sum+=num-- sum = sum+(num-1) It is the same?

26th Apr 2024, 8:26 AM
Рустам Мухамбеталиев
Рустам Мухамбеталиев - avatar
2 Respuestas
+ 3
sum += num--; this statement first adds the current value of num to sum and then decrements num by 1. So, sum will contain the original value of sum plus the original value of num, and after this operation, num will be decreased by 1. sum = sum + (num - 1); and, this statement calculates num - 1, adds the result to the current value of sum, and assigns the result back to sum. So, sum will contain the original value of sum plus the original value of num - 1, but num itself remains unchanged. This anomaly is because of the post-decrement operator -- is used in. Check the comments in the code. You can get clearification abt the outputs. Take a look for clarification, since you didn't clearifying any Language in your tag. Here are few. https://sololearn.com/compiler-playground/cSCk4zDIi8pR/?ref=app https://sololearn.com/compiler-playground/c5mGR61UlStz/?ref=app https://sololearn.com/compiler-playground/cGQB3g7Myv4T/?ref=app
26th Apr 2024, 9:11 AM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
+ 1
thank u very much, im understand
26th Apr 2024, 9:41 AM
Рустам Мухамбеталиев
Рустам Мухамбеталиев - avatar