INCREMENT AND DECREMENT OPERATORS SIMPLIFIED | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

INCREMENT AND DECREMENT OPERATORS SIMPLIFIED

3rd Nov 2016, 4:35 PM
Alabi Oyewumi Emmanuel
Alabi Oyewumi Emmanuel - avatar
2 Answers
+ 5
++i means “increment i IMMEDIATELY,” while i++ means “use the old value of use the old value of i for NOW, but increment i LATER.” EXAMPLES=> int a = 21; int c ; ***************************** c = a++; cout << c c=21 cout << a a=22 ***************************** c = ++a; cout << c c=23 *****************************
3rd Nov 2016, 4:35 PM
Alabi Oyewumi Emmanuel
Alabi Oyewumi Emmanuel - avatar
+ 5
well, think of it this way, you get the value of i but you perform the operations in order, so: x = ++i // increment i; get value of i into x // x and i have the same incremented value x = i++ // get value of i into x; increment i // x has old i value, i has incremented value
3rd Nov 2016, 10:52 PM
Eduard Alexandru
Eduard Alexandru - avatar