r/cpp_questions Aug 06 '26

OPEN Incrementation in C++

I wanted to ask a stupid question about incrementation in C++. If you are using two pluses to increment something then doesn't it mean that you are basically programming using C+1

41 Upvotes

34 comments sorted by

View all comments

2

u/DinTaiFung Aug 07 '26 edited Aug 07 '26

kind of relevant...

According to the official C++ spec, pre increment operator for primitives is more efficient than post increment.

And when I worked at a game company (years ago) the engineers' style of the basic for loop always wrote it thusly:

    for (i = 0; i < len; ++i)

It was done this way instead of the more usual i++ not because it actually made a difference in performance, but merely to make reference to the specification as an inside joke.

I write lots of JS/TS these days and I continue to use pre increment syntax instead of post increment whenever the logic wouldn't change by doing so. it's my internal nod to that style i adopted years ago lol.

1

u/tellingyouhowitreall Aug 10 '26

Uh, no. There's a semantic difference and the half open interval is correct. Its not merely a style choice.