0
im confused when it show (x++) its still 34 then the next example it shows (++x) its added once
explain to me and why?? please
3 Answers
+ 4
Because when you use x++ it basically means that you use the value of x and after that you increment it. Note that you will use the original value first not the increment one.
With ++x it means that you increment x first and then use the value incremented.
Example:
If x=4
System.out.println(x++) prints 4
System.out.println(++x) prints 5
+ 3
x++ is postfix increment so when you use like
System.out.print(x++);
than first it prints the value of x than add one in x,
In other side ++x is known as prefix increment in this it first increase the value of x than print it.
+ 1
in case of x++ firstly it shows the result and then increment by 1 but in case of ++x it first increment by one and then show the result same is the case with --x and x--