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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.