0

Difference between prefix and postfix

I still does not understand about prefix and postfix statements.. what is the difference ??

22nd Nov 2016, 12:30 AM
Afif Asri
Afif Asri - avatar
3 Respuestas
+ 4
Take this example: x = 2; y = ++x; // y is 3, x is 3 Whereas something like this is: x = 2; y = x++; // y is 2, x is 3. It does y = x and then // increments it.
22nd Nov 2016, 1:06 AM
Keto Z
Keto Z - avatar
0
x=2 y=++x means you add first 1 to x then you assign the value x to y. thats why the answer is y=3 x=2 y=x++ means you assign the value of x to y first then you add 1 to x. so the answer will be y=2
22nd Nov 2016, 3:44 AM
Junjie Gono
Junjie Gono - avatar
0
++x is prefix increment. it will add 1 to the variable 'x' in place. x+=1 is the same as: ++x x++ is postfix increment. it will first return the variable and only then add 1 to it. temp=x x+=1 return temp is the same as: x++
22nd Nov 2016, 5:49 AM
asdadasdsaczxc