- 2

Why not a++?

3rd Dec 2017, 10:53 AM
Esther Mona
Esther Mona - avatar
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
3rd Dec 2017, 11:53 AM
Peerzada Burhan
Peerzada Burhan - avatar
+ 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;
3rd Dec 2017, 11:52 AM
Dima Makieiev
Dima Makieiev - avatar
0
I just wanted to know the difference between a++ and ++a
3rd Dec 2017, 11:25 AM
Esther Mona
Esther Mona - avatar