Compound statement

One of the most useful forms of statement is the compound statement or block. This brackets together a number of declarations and statements and makes them into a single statement. Thus, in a C program with a conditional statement, the syntax says that only one statement is allowed in each branch. If we wish to perform several statements if the condition is true, we need to use a compound statement to bracket them.

A compound statement is a sequence of statements enclosed in braces.

Note: in C the semi-colon is part of a statement, not a separator between statements. You must write a semi-colon before the closing brace of a compound statement.

compound-statement
		{ declaration-listopt statement-listopt }

declaration-list
		declaration
		declaration-list declaration

statement-list
		statement
		statement-list statement

Exercises on this section.


Next.

Back to Contents page.