What is increment & decrement operator in java with example ?
Answers
Answered by
4
Answer in easiest language is attached below..
Hope it vl help....
Attachments:
kvnmurty:
good
Answered by
5
Increment operator increments the value of an integer variable and float or double variable by 1.
decrement reduces its value by 1. The operand must have an L value ie., an address in storage.
These operators are unary.
double x = 3.5 ; int y = 1;
x++ ; // x is now 4.5
-- x; // x is now 3.5
y ++ ; // y is now 2
--y ; // y is now 1
x++ is equivalent to (x = (x +1))
--y is equivalent to (y = (y -1))
++ and -- have higher precedence than binary operators.
decrement reduces its value by 1. The operand must have an L value ie., an address in storage.
These operators are unary.
double x = 3.5 ; int y = 1;
x++ ; // x is now 4.5
-- x; // x is now 3.5
y ++ ; // y is now 2
--y ; // y is now 1
x++ is equivalent to (x = (x +1))
--y is equivalent to (y = (y -1))
++ and -- have higher precedence than binary operators.
Similar questions