+ 1

Confused with increment operators

Explain this please : ++i * 3 being equivalent to (i += 1) * 3, but not to i += 1 * 3 (which is equivalent to i += 3).. Confused with them!

30th May 2017, 4:58 PM
Devika S Nair
Devika S Nair - avatar
2 Answers
+ 8
++i is equivalent to i=i+1, So as you describe at 1st, ++i*3 is equivalent to (i+=1)*3, and not i+=1*3. For pre increment and post increment confusions, refer- https://code.sololearn.com/cjHQRJUG5NTf/?ref=app
30th May 2017, 5:26 PM
Sachin Artani
Sachin Artani - avatar
+ 3
Thank you..Dat was an awesome piece of code :)
30th May 2017, 6:49 PM
Devika S Nair
Devika S Nair - avatar