- 2
Why not a++?
3 Answers
+ 5
++a first increments the value of "a" by 1 and then uses it where as a++ uses the value of "a" then increments it.
eg
int a = 0;
int b = ++a;
Here above value of "a" first becomes 1 and then "b" is assigned the value of a. In short both "a" and "b" are now 1
int a = 0;
int b = a++;
Here above first value of "a" is assigned to "b" then incremented by 1. In short "b" is equal to 0 and "a" becomes 1
+ 1
Difference in the time when the operation on the variable will be performed, if I am not mistaking. e.g. int a =1; ++a<2 >> false; a++<2 >> true;
0
I just wanted to know the difference between a++ and ++a