What is the difference between i++ and ++i | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

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

please answer, i'm having test tomorrow

16th Sep 2017, 11:46 AM
francis mokoena
francis mokoena - avatar
6 Answers
+ 8
In the beginning.beginner will think like what @Ryan Ward said but the truth is ++i will do increment first then return the i i++ will make copy form of i then do increment after there return that copy form which mean that ++i is faster than i++
16th Sep 2017, 11:56 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 14
@francis that tick is for best (which helped you the best) answer. not so you can tick your own answer. https://www.sololearn.com/discuss/286200/?ref=app https://www.sololearn.com/discuss/345567/?ref=app
16th Sep 2017, 12:32 PM
Lord Krishna
Lord Krishna - avatar
+ 11
https://www.sololearn.com/discuss/489143/?ref=app
16th Sep 2017, 11:54 AM
P R
P R - avatar
+ 6
one increments before using the value and the other increments after using the variable. Google prefix and postfix if you need more info.
16th Sep 2017, 11:48 AM
Ryan Ward
Ryan Ward - avatar
+ 6
i++ : "i" value is read by the compiler and increments the value by 1, like i=I+1. ++i : first it increments the value by 1 and uses the "i" value, like 1+i= i.
16th Sep 2017, 4:51 PM
Deepak
Deepak - avatar
+ 4
thnx for help
16th Sep 2017, 12:19 PM
francis mokoena
francis mokoena - avatar