+ 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
5 Answers
+ 6
Just here to dump more links:
https://www.sololearn.com/Discuss/407846/?ref=app
+ 5
https://www.sololearn.com/Discuss/217288/?ref=app
+ 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 */
+ 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