Home Segments Index Top Previous Next

137: Mainline

A compound statement, also known as a block, is a group of statements surrounded by braces. A compound statement can have its own variable declarations.

The scope of the variables declared in a compound statement is the compound statement itself. The extent of such variables is the time during which the compound statement is executed.

Note that function bodies are compound statements. You see other examples in the hardcopy version of this book, because compound statements are used liberally inside C++'s if and if-else statements.