x: 100 y: 100
When a variable is not part of a larger expression it makes no difference if you use the prefix operator or the postfix operator. For example:
count++ ; ++count ;
For example, the following loop will print the values from 0 to 9, just as did the previous version (which used a postfix operator):
int counter = 0; while ( counter < 10 ) { System.out.println("counter is now " + counter ); ++counter ; }
It is wise to use the ++
operator
only with an isolated variable,
as above.
Using it in more complicated expressions is never necessary,
but can lead to nasty bugs.
Java allows this only because it is familiar to "C"
programmers.
The language "C" did this because it was familiar
to assembly language programmers of the PDP-8 computer!