Declarations as statements - declarations in conditions
Introduce and initialize a variable at the place where it is first used
It is possible to delare variables in a condition of an if statement
- Declarations inside blocks
- C89: All declarations appear before the first statement
- C99 and C++: declarations and statements can be mixed
- Avoids having all declarations first in block, and assignments later in the block
- Declarations in the condition of an if statement
- The scope of such a name is the rest of the if, including the else part
- Serves as a scope restriction, compared with a declaration just before the if statement
Declarations before statements - C89 Style.
A declaration is a statement in C++.
A declaration in the condition of an if.