Difference between a=a+1 and a+=1 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Difference between a=a+1 and a+=1

Is there any difference between a=a+1 and a+=1? Not in result But when the compiler compiles it

22nd Jan 2019, 3:12 AM
Prakash Joshi
Prakash Joshi - avatar
2 Answers
+ 1
a=+1 is completely different from a+=1. I think you made a very common typo there. Ignoring that, there is no difference between the both. a+=1 has always been regarded to be semantically the same as a=a+1.
22nd Jan 2019, 3:32 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
As both formats are same but the difference is in their execution... According to Java and C.. As a=a+1 consist of two linear Operations of addition and assigning Where as a+=1 consist of both operations executing in parallel. That's the reason it's more preferred.
8th Feb 2019, 12:46 PM
Harsh Dagar
Harsh Dagar - avatar