im confused when it show (x++) its still 34 then the next example it shows (++x) its added once | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

21st Sep 2016, 2:12 PM
Domasian arvin karl
Domasian arvin karl - avatar
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
25th Sep 2016, 9:11 AM
Sebastian
+ 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.
21st Sep 2016, 6:51 PM
Pradeep Saini
Pradeep Saini - avatar
+ 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--
26th Sep 2016, 8:22 AM
Kashish Gupta
Kashish Gupta - avatar