Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Operator question. +=

So my friend gave me some source code to start out with so I could review and understand it and I have a question about it, but since he's not online I thought I would try here, mainly I don't quite understand this line.

num += i;

Essentially, this is the same as

num = num + i 

right?

If you need more details please tell me! I look forward to hearing your replies soon.

like image 643
samuraiseoul Avatar asked Dec 10 '25 22:12

samuraiseoul


1 Answers

From ISO C++03 (Section 5.17/7)

The behavior of an expression of the form E1 op= E2 is equivalent to E1 = E1 op E2 except that E1 is evaluated only once.

like image 51
Prasoon Saurav Avatar answered Dec 12 '25 11:12

Prasoon Saurav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!