0
++ Confusion in java
++a , a++ what is difference
3 ответов
+ 6
Devashish kumar ,
here a short description:
=> *pre-increment* operator: ++x
is used to increment the value of variable `x` **before** using it in an expression.
=> *post-increment* operator: x++
is used to increment the value of variable `x` **after** executing the expression.
+ 4
++a : pre-increment
a++ : post-increment
+ 2
EXAMPLE - pre-increment
x = 5;
y = ++x; (increment x to 6, then assign 6 to y)
EXAMPLE - post-increment
a = 5;
b = a++; (assign 5 to b, then increment a to 6)
Both cases have the side-effect of incrementing and saving the variable.
Just a question whether you access the value of the variable before or after the increment happens.