What do statements like x-=y+=z mean? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

What do statements like x-=y+=z mean?

There are 2 assignment operators used. So this is confusing for me. Please help.

7th Jul 2019, 5:06 AM
Mousin Ahanger
Mousin Ahanger - avatar
2 Answers
+ 5
Are you sure its x-=y+=z or you ment x-=y; y+=z; Because x -= y; simply means x = x - y; but it's shortened way of syntax y += z; means y = y + z; This can be also used with more operations.. a*=a;
7th Jul 2019, 5:30 AM
Krysto Foxik 🐥
Krysto Foxik 🐥 - avatar
0
If assignment operators follow the left-to-right operation precedence, then: x -= y += z would first subtract y from x: x -= y Then it would add z to y: y += z In end: x = x - y y = y + z z = z
7th Jul 2019, 8:00 AM
Seb TheS
Seb TheS - avatar