A block statement, or compound statement, lets you group any number of data definitions, declarations, and statements into one statement. All definitions, declarations, and statements enclosed within a single set of braces are treated as a single statement. You can use a block wherever a single statement is allowed.
In C, definitions and declarations must come before the statements in a statement block.
Redefining a data object inside a nested block hides the outer object while the inner block runs. However, defining several variables that have the same identifier can make a program difficult to understand and maintain. You should avoid redefining identifiers within nested blocks. If a data object is usable within a block and its identifier is not redefined, all nested blocks can use that data object.
Initialization of an auto or register variable occurs each time the block is run from the beginning. If you transfer control from one block to the middle of another block, initializations are not always performed. You cannot initialize an extern variable within a block.
Unlike ISO/ANSI C, in C++ it is an error to jump over a declaration or definition containing an initializer.
The following code produces an error in C++:
goto skiplabel; int i=3 // error, jumped over declaration of i with initializer skiplabel: i=4;
Block Scope
Data Declarations
File
Scope Data Declarations
Storage
Class Specifiers
Type
Specifiers