+ 4
Guys, what is the difference between x+, x++, ++x and the same as x-, x--, --x in java? thank you in advance!
2 Respostas
+ 9
if you write x+ or x- it will cause an error because there is no meaning in them.
However for x++ and x-- there is no difference when used alone, the difference is when you use them in an expression.
a++ evaluates a, then increments it (post-incrementation).
++a increments a, then evaluates it (pre-incrementation).
Example:
int a = 1;
int b = a++; //b = 1, a = 2
System.out.println(b); //prints 1
a = 1;
b = ++a; //b = 2, a = 2
System.out.println(b); //prints 2
+ 6
haha thanks Lara:p