Incrementing and Decrementing
Almost every modern processor can increment and decrement in one machine instruction (and many can do it in a fraction of an instruction). Use of the ++ and -- operators enables C++ compilers to use special increment and decrement instructions in the code they generate from your C++ source. So by using
Index++;
rather than
Index = Index + 1;
you can help the compiler and speed up your program.
It is also possible that the compiler can optimize
Index+= 3;
to run faster than
Index = Index + 3;
for similar reasons.
Note that this will not help with overloaded operators, however, because they have user-defined implementations.
Get SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.