+ 1
What is the difference between ++i and i++?Â
7 Answers
+ 4
You are welcomeđđ
+ 4
Hope you can find the information here in these posts, and please try using the search bar next time before posting a question:
https://www.sololearn.com/discuss/718883/?ref=app
https://www.sololearn.com/discuss/790112/?ref=app
https://www.sololearn.com/discuss/666244/?ref=app
https://www.sololearn.com/discuss/315483/?ref=app
+ 4
i++ does not change a variable's value. ++i increases a variable's value by 1
+ 2
Thanks
+ 1
@Muhammad
That is wrong, i++ changes a variable's value too, but rather after evaluating in whatever it is used.
int i = 5; i++; cout << i;
for example still results in i being 6!
+ 1
@Muhammed
If you would print a again in another Print-Statement, you would see that a is now 4.
You can see it here, I did it for you:
https://code.sololearn.com/c6H53OSXiu57/?ref=app
It seems you havent understood Postfix and Prefix completely, so I wrote this code and commented everything (sorry its in C++, but thats my main lanuage and the one im best at):
https://code.sololearn.com/cSBy9eDUPcW1/?ref=app
I hope this helps you understanding the difference between those two, because teaching wrong things might cause trouble for the ones trying to learn it!
And, by the way, just a question of logic, why would a++ even exist if it didnt increment by one, what would be it's use?