Statements and Blocks
An expression such as x = 0
or i++
or printf(...)
becomes a statement when it is followed by a semicolon, as in:
x = 0;
i++;
printf(...);
In C, the semicolon is a statement terminator, rather than a separator as it is in languages like Pascal.
Braces {
and }
are used to group declarations and statements together into a compound statement, or block, so that they are syntactically equivalent to a single statement. The braces that surround the statements of a function are one obvious example; braces around multiple statements after an if
, else
, while
, or for
are another. (Variables can be declared inside any block; we will talk about this in Chapter 4.) There is no semicolon after the right brace that ends a block.