0

Postfix and Prefix Increments

Was taking the lesson on increments and decrementos in C++ today and didn’t fully understand the explanation given on the difference between writing x++ or ++x. Can anyone explain it in a different way to help?

28th Apr 2019, 5:30 PM
Becca
Becca - avatar
6 ответов
0
PapaBT it’s the other way around, prefix first increments.
28th Apr 2019, 7:20 PM
Sergiu Panaite
Sergiu Panaite - avatar
0
Sorry - yes of cause Sergiu is right :-(
28th Apr 2019, 8:06 PM
PapaBT
PapaBT - avatar
0
PapaBT Sergiu Panaite thank you both for the help, so the way i understand it now is that: if x = 5, then x++ is used, in that line x would still display as five but in the next line would be increased to six. If x = 5 and ++x is used, its increased first so that on the same line x now displays as six. Am I right with that?
28th Apr 2019, 9:06 PM
Becca
Becca - avatar
0
yes, correct
29th Apr 2019, 8:37 AM
Sergiu Panaite
Sergiu Panaite - avatar
- 1
++x X will be incremented after the line is processed. X has the old value for processing the rest of the line. x++ X will be incremented emidiate, and has the new value for processing the rest of the line. If it stands alone in a line, both expressions produce the same output.
28th Apr 2019, 6:45 PM
PapaBT
PapaBT - avatar