+ 1
Please tell me the difference?(Related to incrementation)
++x and x++ What's the difference and where they are helpful. Please and Thanks
3 Answers
+ 5
++x is Pre increment meaning, increment is done first. For example,
y = ++x
means x = x + 1 and y = x.
If x is 1 initially, y becomes 2.
x++ is Post increment meaning, increment is done last. For example,
y = x++
means y = x and x = x + 1.
If x is 1 initially, y becomes 1.
+ 1
quick example
pre increment means value is incremented prior to being used, post increment means value is incremented after it was used
int i = 1;
System.out.println (++i); // i is now 2. prints 2
vs
int i = 1;
System.out.println (i++); // prints 1, but i is now 2
0
Thanks