Difference between ++a and a++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Difference between ++a and a++

14th Jan 2017, 1:41 AM
Hel
Hel - avatar
3 Answers
+ 8
Look lessons.
14th Jan 2017, 7:49 AM
Sergey
+ 5
int a = 2; int b = ++a; //This will give the value of 3 to b and the value of a will be 3 too int b = a++; //This will give the value of 2 to b and then the value of a will be 3
14th Jan 2017, 1:46 AM
Kawaii
Kawaii - avatar
+ 1
++a is pre-increment. It increases the value of 'a' by 1 before executing that line. Operation on that line will use the new value of 'a'. a++ is post-increment. It increases the value of 'a' by 1 after executing that line. Operation on that line will use the original value of 'a' then only will add 1 to 'a'.
14th Jan 2017, 7:51 AM
Yi Jing Chai
Yi Jing Chai - avatar