Most statements in C++ end with a semicolon. An expression, such as ival + 5
, becomes an expression statement when it is followed by a semicolon. Expression statements cause the expression to be evaluated and its result discarded:
ival + 5; // rather useless expression statement
cout << ival; // useful expression statement
The first statement is pretty useless: The addition is done but the result is not used. More commonly, an expression statement contains an expression that has a side effect—such as assigning a new value to a variable, or printing a result—when it is evaluated.