-1

Why is a still 0 after the following operation?

int a = 0;
a+=a++;

1 Answers1

6

a++ increments a but returns its previous value 0.

That's why a+=a++, which is equivalent to a=a+a++, sets a back to 0+0;

Eran
  • 387,369
  • 54
  • 702
  • 768