+ 3

Difference between these

what is the difference between for (a=0;a<5;a++) and for (a=0;a<5;++a)

9th Sep 2017, 6:48 AM
Ponraj Hbk
Ponraj Hbk - avatar
3 Answers
+ 13
@Ponraj The version that has ++a can be ever so slighty faster as no temporary copy of the a variable needs to be created. in most instances the time difference is negligible. http://www.cplusplus.com/forum/beginner/22073/
9th Sep 2017, 7:07 AM
jay
jay - avatar
+ 12
@Shawn. Indeed! Still good knowledge to keep in the back of ones mind though. not all compilers are created equal. but in this respect you are correct. most if not all will change it (a++) to the most efficient version
9th Sep 2017, 8:05 AM
jay
jay - avatar
+ 10
The compiler would be able to do a great job at optimising your code so both won't make much difference (if any difference exist in the end, that is).
9th Sep 2017, 7:32 AM
Hatsy Rei
Hatsy Rei - avatar