+ 2

How exactly work the increment operator?

I don't understand how work ++x and x++

16th Jul 2018, 7:03 PM
Ianel Tombozafy
Ianel Tombozafy - avatar
3 Answers
+ 4
Ianel Tombozafy Post Increment => x++ Pre Increment => ++x Post means after, so Post Increment means "Increase after" Example ======== int x = 2; int y = x++ ; This statements simply says "Assign the value of x(2) to y, THEN increment x by 1 after the statement So that y= 2, x =3" Pre means before, so Pre Increment means "Increase first, then carry out the statement" Example ======== int x = 3 int y = ++x The statement simply says "First of all increase "x" by 1, then add the new value of "x" to "y", so that x= 3, y= 3 as well "
16th Jul 2018, 7:14 PM
Dlite
Dlite - avatar
+ 1
Ianel Tombozafy x++ : Use x, then increment it by 1. ++x: Increment x by one, then use x.
26th Aug 2018, 2:29 PM
Fenomalala Ranaivoson
Fenomalala Ranaivoson - avatar
+ 1
Ok thanks
26th Aug 2018, 4:50 PM
Ianel Tombozafy
Ianel Tombozafy - avatar