O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required