0

Increment and decrement simplified

i dont get how post fix and pre fix works pls explain :(

27th Oct 2016, 10:56 AM
Deneb Ho
2 Respuestas
+ 4
++n increments n, then evaluates it (pre-inctementation). n++ evaluates n, then increments it (post-incrementation). They are both equivalent to n=n+1 by themselves, the difference is when they are used in an expression. int a = 1; int b = ++a; cout << a << endl; //prints 2 cout << b << endl; //prints 2 a = 1; b = a++; cout << a << endl; //prints 2 cout << b << endl; //prints 1
27th Oct 2016, 11:13 AM
Zen
Zen - avatar
+ 2
• ++i means “increment i immediately,” while i++ means “use the old value of use the old value of i for now, but for now, but increment i later.”
3rd Nov 2016, 4:13 PM
Alabi Oyewumi Emmanuel
Alabi Oyewumi Emmanuel - avatar