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?
6 Respuestas
0
PapaBT it’s the other way around, prefix first increments.
0
Sorry - yes of cause Sergiu is right :-(
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?
0
yes, correct
- 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.