+ 1

What is the difference between ++i and i++? 

25th Oct 2017, 7:41 PM
AyouB Tamous
AyouB Tamous - avatar
7 Answers
+ 4
You are welcome😉😉
26th Oct 2017, 10:58 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 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
25th Oct 2017, 7:50 PM
Shadow
Shadow - avatar
+ 4
i++ does not change a variable's value. ++i increases a variable's value by 1
26th Oct 2017, 10:52 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
26th Oct 2017, 11:08 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 2
Thanks
26th Oct 2017, 10:13 AM
AyouB Tamous
AyouB Tamous - avatar
+ 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!
26th Oct 2017, 11:04 AM
Shadow
Shadow - avatar
+ 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?
26th Oct 2017, 11:39 AM
Shadow
Shadow - avatar