+ 1

Prefix and postfix

Can someone show me the difference of x++ and ++x

2nd Jan 2018, 7:57 AM
Alan
Alan - avatar
4 Respostas
+ 16
x++ increments after the line ends and ++x increments on the same line.... for eg.:- int x=4; int y=x++; //here y=4. & x will be incremented in next line cout<<x<<y; outputs:- 54 eg.2:- int x=4; int y=++x; //here x is incremented on the same line & so y=5. cout<<x<<y; outputs:- 55 consider 1 more eg.:- int x=4; x+=x++; // value of x becomes 8 & then it gets incremented on next line... cout<<x; outputs:--9 eg:-2 int x=4; x+=++x; // x=x+(++x) here value of x becomes 5 first & then operated.. cout<<x; outputs:--10
2nd Jan 2018, 11:41 AM
🌛DT🌜
🌛DT🌜 - avatar
+ 11
x++ increase expression after line with this part of code. ++x - while doing
2nd Jan 2018, 8:29 AM
Alexander Malcev
Alexander Malcev - avatar
+ 2
have a look at these lesson https://www.sololearn.com/learn/CPlusPlus/1610/?ref=app the are in total 5 slides go through all
2nd Jan 2018, 12:18 PM
Ankush Kumar
Ankush Kumar - avatar