count++
and ++count
are short for count=count+1
. The assignment is built-in, so it makes no sense to assign it again. The difference between count++
(also known as postfix) and ++count
(also known as prefix) is that ++count
will happen before the rest of the line, and count++
will happen after the rest of the line.
If you needed to separate count=count++
, you get the following:
count = count; count = count+1;
Now you can understand why postfix will not give you a warning: in the end, something is really changing.
If you split count=++count
, you get the following:
count = count+1; count = count;
As you can see, the second line of code is useless and why the compiler warns you.
source share