# Embedded C

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

In C or C++ both a+=x and a = a+x will increment the value of a by x. But there is a difference between these two is how fast it is executed and the memory aceess.

a+=1 will increment the value of a by 1. For example the value of a is 5 means after completing this expression a will be 6. The same is applicable for  a = a+1.

When we see the expression a+=1 a is coming only once, that is a is a is not read and it is incremented directly. So only write operation occurs. This will reduce the time.

When we see the expression a = a+1 a is coming two times, that is a is read once and write once. So this will process two operations. This will impact in increasing the time.

So timing and memory access is the differences between a+=x and a = a+ x.

This is applicable for all the expression shown below.
a+=x                ==                a = a + x
a-=x                ==                a = a - x
a*=x                ==                a = a * x
a/=x                ==                a = a / x