Increment Operator
In java, there are two types of increments operators
- Pre-Increments b = ++a;
- Post-Increments b = a++;
Decrement Operator
In java, there are two types of decrements operators
- Pre-Decrements b = --a;
- Post-Derement b = a--;
Lets understand more by following examples:-
int a=10;
int b;
Expression initial value of a value of b after the completing expression final value of a
b = ++a 10 11 11
b = a++ 10 10 11
b = -- a 10 9 9
b = a-- 10 10 9
Rule 1.
We can apply increment & decrement operators only for variables but not for constant value.
If we are trying to apply for constant value then we will get Compile Time Error.
example 1:-