Increment and Decrement Operator in Java : It is one of the variation of “ Arithmetic Operator “. Increment and Decrement Operators are...
August 10, 2017
Increment and Decrement Operator in Java :
- It is one of the variation of “Arithmetic Operator“.
- Increment and Decrement Operators are Unary Operators.
- Unary Operator Operates on One Operand.
- Increment Operator is Used to Increment Value Stored inside Variable on which it is operating.
- Decrement Operator is used to decrement value of Variable by 1 (default).
Types of Increment and Decrement Operator :
- Pre Increment / Pre Decrement Operator
- Post Increment / Post Decrement Operator
Pre-Increment Operator :
- “++” / “--” is written before Variable name.
- Value is Incremented First and then incremented value is used in expression.
- “++” / “--” cannot be used over “Constant” of “final Variable“.
Post-Increment Operator :
- “++” / “--” is written after Variable name.
- num1++ will increment value inside “num1” variable after assigning old value to itself.
- New Value of num1 = 2.
- “++” / “--” cannot be used over “Constant” of “final Variable“.