CATEGORII DOCUMENTE |
A declaration-statement declares a local variable or constant. Declaration statements are permitted in blocks, but are not permitted as embedded statements.
declaration-statement:
local-variable-declaration ;
local-constant-declaration ;
A local-variable-declaration declares one or more local variables.
local-variable-declaration:
type variable-declarators
variable-declarators:
variable-declarator
variable-declarators , variable-declarator
variable-declarator:
identifier
identifier = variable-initializer
variable-initializer:
expression
array-initializer
The type of a local-variable-declaration specifies the type of the variables introduced by the declaration. The type is followed by a list of variable-declarators, each of which introduces a new variable. A variable-declarator consists of an identifier that names the variable, optionally followed by an "=" token and a variable-initializer that gives the initial value of the variable.
The value of a local variable is obtained in an expression using a simple-name (7.5.2), and the value of a local variable is modified using an assignment (7.13). A local variable must be definitely assigned (5.3) at each location where its value is obtained.
The scope of a local variable starts immediately after its identifier in the declaration and extends to the end of the block containing the declaration. Within the scope of a local variable, it is an error to declare another local variable or constant with the same name.
A local variable declaration that declares multiple variables is equivalent to multiple declarations of single variables with the same type. Furthermore, a variable initializer in a local variable declaration corresponds exactly to an assignment statement that is inserted immediately after the declaration.
The example
void F()
corresponds exactly to
void F()
A local-constant-declaration declares one or more local constants.
local-constant-declaration:
const type constant-declarators
constant-declarators:
constant-declarator
constant-declarators , constant-declarator
constant-declarator:
identifier = constant-expression
The type of a local-constant-declaration specifies the type of the constants introduced by the declaration. The type is followed by a list of constant-declarators, each of which introduces a new constant. A constant-declarator consists of an identifier that names the constant, followed by an "=" token, followed by a constant-expression (7.15) that gives the value of the constant.
The type and constant-expression of a local constant declaration must follow the same rules as those of a constant member declaration (10.3).
The value of a local constant is obtained in an expression using a simple-name (7.5.2).
The scope of a local constant extends from its declaration to the end of the block containing the declaration. The scope of a local constant does not include the constant-expression that provides its value. Within the scope of a local constant, it is an error to declare another local variable or constant with the same name.
A local constant declaration that declares multiple constants is equivalent to multiple declarations of single constants with the same type.
Politica de confidentialitate | Termeni si conditii de utilizare |
Vizualizari: 820
Importanta:
Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved