0
Is there a better way to explain increaments?
I am still a little bit confused about increaments like x++ or ++x especially when it comes to the prefix/postfix part. Could someone please try explaining it in a different way than they did in the lesson? Thanks!
3 Answers
+ 2
simmilar question
https://www.sololearn.com/Discuss/77467/?ref=app
+ 1
I'll try to give an example, I hope it will help:
y = x++; means the same as y = x; x = x + 1.
y = ++x; means the same as x = x + 1; y = x.
Basically x++ means that x is used before it is incremented, whereas ++x means that you increment x before using it. I don't remember how they explained it in the lesson, but this is the best way I could explain it.
0
Prefix example:
int x = 3;
int y = ++x;
// x is 4, y is 4
Postfix example:
int x = 3;
int y = x++;
// x is 4, y is 3



