That's why it's called the "post-incrementing operator". Essentially, everything is an expression which results in a value. a + 1
is an expression which results in the value 124. If you assign this to b
with b = a + 1
, b
has the value of 124. If you do not assign the result to anything, a + 1
will still result in the value 124, it will just be thrown away immediately since you're not "catching" it anywhere.
BTW, even b = a + 1
is an expression which returns 124. The resulting value of an assignment expression is the assigned value. That's why c = b = a + 1
works as you'd expect.
Anyway, the special thing about an expression with ++
and --
is that in addition to returning a value, the ++
operator modifies the variable directly. So what happens when you do b = a++
is, the expression a++
returns the value 123 and increments a
. The post incrementor first returns the value, then increments, while the pre incrementor ++a
first increments, then returns the value. If you just wrote a++
by itself without assignment, you won't notice the difference. That's how a++
is usually used, as short-hand for a = a + 1
.
This is pretty standard.