++I vs I++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

++I vs I++

I have been searching and researching for differences between I++ & ++I and I'm still unable to understand ++I, I completely understand I++ incremental . can anybody explain it in terms how the incremental is going to be like

10th Jun 2017, 11:01 AM
Mohammad Farid
Mohammad Farid - avatar
5 Answers
+ 6
10th Jun 2017, 1:59 PM
Hatsy Rei
Hatsy Rei - avatar
+ 5
https://www.sololearn.com/Discuss/217288/?ref=app
10th Jun 2017, 11:26 AM
Pixie
Pixie - avatar
+ 5
to understand this first u have to understand how a compiler interpretes mathematical expressions when you use variables in mathematical expressions the compiler uses the variable's value instead of the variable itself.for e.g. int x=5; int y=7; z= x+y; /* here compiler uses the value of x and y like this z= 5+7 = 12 */ in case of I++ the compiler first uses that value in the expression and then changes the original value of the variable. for e.g. int I = 5; int K = I++; /*   here 5 is assigned to K but after this expression is evaluated the value of a becomes 6  */ in case of ++I the opposite happens.the compiler first changes the original value of the variable  and then uses in the expression. for e.g. int I = 5; int K = ++I; /* here value of I first changes to 6 and this value is assigned to K so the value of K too becomes 6 */
10th Jun 2017, 12:10 PM
cHiRaG GhOsH
cHiRaG GhOsH - avatar
10th Jun 2017, 11:37 AM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
+ 1
a = 5; b = ++a; //a = 6; b = 6, PRE increment, incremented before it's use c =5; d = c++; //c = 6; d = 5, POST increment, incremented after it's use
10th Jun 2017, 4:07 PM
Andrés04_ve
Andrés04_ve - avatar