New course! Every coder should learn Generative AI!
Try a free lesson- 1
Difference between ++a and a++
3 Answers
+ 8
Look lessons.
+ 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
+ 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'.