Yes.
| Expression | Operation | Example | Result |
|---|---|---|---|
| x++ | use the value in x, then add 1 | int x = 10; int y; y = x++ ; | x is 11; y is 10 |
| ++x | add 1, then use the value in x | int x = 10; int y; y = ++x ; | x is 11; y is 11 |
| x-- | use the value in x, then subtract 1 | int x = 10; int y; y = x-- ; | x is 9; y is 10 |
| --x | subtract 1, then use the value in x | int x = 10; int y; y = --x ; | x is 9; y is 9 |
The operator -- is
a postfix and a prefix decrement operator.
The postfix -- operator decrements a variable after using its value.
The prefix -- operator decrements a variable before using its value.
Inspect the following code:
int x = 99;
int y = 10;
y = --x ;
System.out.println("x: " + x + " y: " + y );
What does this fragment write out?