What is the importance of post increment and pre increment in C++?

160 views

What is the importance of post increment and pre increment in C++?

In: 7

7 Answers

Anonymous 0 Comments

In addition to what everyone else has said about using pre or post increment in more complex statements and assignments, there *was* also a further reason for using pre increment over post increment in certain circumstances.

When incrementing STL (or other similar) iterators in a loop then pre increment was preferred as it was significantly faster. With more modern compilers this is no longer the case, but you’ll still see a lot of older code, or code written by older programmers, using pre increment for this reason and habit. I myself still always use pre increment even in other languages like C# because I’ve had it drilled into me from > 20 years of programming.

See: https://eklitzke.org/stl-iterators-and-performance-revisited

You are viewing 1 out of 7 answers, click here to view all answers.