+ 1
Can you explain me the differences of ++x(pre) and x++(post)
4 ответов
+ 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.
+ 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
+ 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).
0
If you want u can check my codes. I nade some comments over that