Increment Expression Acts Like a Standalone Statement

The increment expression in the for statement acts like a standalone statement at the end of for statement’s body. Therefore, for integer counters, the expressions

counter = counter + 1 counter += 1 ++countercounter++

are all equivalent in the increment expression (when no other code appears there). The integer variable being incremented here does not appear in a larger expression, so both preincrementing and postincrementing actually have the same effect.

Image Common Programming Error 5.1

Placing a semicolon immediately to the right of the right parenthesis of a for header makes the body of ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

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