0

Please help me i cant understand the difference between x++ and ++x

I did not understand

30th Oct 2016, 4:16 PM
Maroun Matar
Maroun Matar - avatar
4 Réponses
+ 2
x++ means use then change while ++x means change then use
30th Oct 2016, 5:27 PM
Piyush Palta
Piyush Palta - avatar
+ 1
thanks this was very helpefull
30th Oct 2016, 4:36 PM
Maroun Matar
Maroun Matar - avatar
0
x++ wil plus 1 after use ++x will plus 1 before use Example int y=2; int x=3; int sum0, sum1, sum2; sum0 = y+x // sum0 = 5 sum1 = y+(++x) // sum1= 6 at this line -> 2+(4) sum2 = y+(x++) // sum2 = 5 at this line -> 2+(3) after this line if you use x, x will equal to 4
30th Oct 2016, 4:28 PM
Pimpat
Pimpat - avatar
0
int x=5; cout<<x++<<endl;//Output 5, then x=6 x=5; cout<<++x<<endl;//x=6 then output 6
30th Oct 2016, 5:44 PM
Leo Flame
Leo Flame - avatar