+ 1

Can you explain me the differences of ++x(pre) and x++(post)

5th Jan 2017, 1:37 AM
Michael
Michael - avatar
4 Answers
+ 5
++x increment before the operation. Lets say this: x = 1 alert(++x) //this will show 2. and X value will be two. //now again with post x=1 alert(x++) //this with show 1, but the value will be 2 after the operation, alert in this case.
5th Jan 2017, 1:43 AM
Nahuel
Nahuel - avatar
+ 1
++x increments before using x, x++ increments after. Interestingly there are differences between languages: x=9; x+=++x; //result is 20 in c++ but 19 in c# https://code.sololearn.com/cNNc6ZyivFr3/?ref=app https://code.sololearn.com/czfsI1LiU800/?ref=app
5th Jan 2017, 4:08 AM
ifl
ifl - avatar
+ 1
try this in c++ int x=1; cout<<x; cout<<x++; cout<<++x; this code outputs: 1,1,3 the first, outputs value of x, (prints 1) the second, first outputs value of x (prints 1) AND THEN increases its value by 1, (now x is 2) the third, first increases its value by 1(2+1=3) AND THEN prints its value (x=3).
5th Jan 2017, 7:41 AM
Mahdi Afshar
Mahdi Afshar - avatar
0
If you want u can check my codes. I nade some comments over that
5th Jan 2017, 4:10 PM
Jonjarm