4.1 Expression Statements

An expression statement computes an expression, such as a function call or assignment. The expression result is discarded, so the expression is typically evaluated for its side effects. (See Chapter 3 for details about expressions.) The statement syntax is simply an optional expression followed by a semicolon:

expr ;

or:

;

A statement with no expression is called a null statement. Null statements are most often used for loops when no code is needed in the loop body.

Here are several examples of expression statements:

42;          // Valid but pointless

cout << 42;  // More typical

x = y * z;   // Remember that assignment is an expression

;            // Null statement