I have been working with C++ for many years, but just realized something fishy about incremental assignment.
I have this snippet
a = 4;
b = 2;
c = 0;
c = c + a > b; printf("a: %d\tb: %d\tc: %d\n",a,b,c);
c = c + a > b; printf("a: %d\tb: %d\tc: %d\n",a,b,c);
c += a < b; printf("a: %d\tb: %d\tc: %d\n",a,b,c);
c += a > b; printf("a: %d\tb: %d\tc: %d\n",a,b,c);
c += a > b; printf("a: %d\tb: %d\tc: %d\n",a,b,c);
And the result is
a: 4 b: 2 c: 1
a: 4 b: 2 c: 1
a: 4 b: 2 c: 1
a: 4 b: 2 c: 2
a: 4 b: 2 c: 3
If you note, the first two lines are the same. Or 'c' doesn't get updated after the first c = c + a > b; However, the value of c gets updated when we use the incremental assignment +=
Any thoughts?