Local Variables
A variable declared inside a function is local. The scope of a local variable is limited to the function range inside which it is declared. Local variable can be initialized by outcome of any expression. Every call of the function initializes a local variable. Local variables are stored in memory area of the corresponding function.
Example:
int somefunc() |
Scope of a variable is a program part, in which a variable can referred to. Variables declared inside a block (at the internal level), have the block as their scope. The block scope start with the variable declaration and ends with the final right brace.
Local variables declared in the beginning of a function also have the scope of block, as well as function parameters that are local variables. Any block can contain variable declarations. If blocks are nested and the identifier in the external block has the same name as the identifier in the internal block, the external block identifier is hidden, until the operation of the internal block is over.
Example:
void OnStart() |
This means that while the internal block is running, it sees values of its own local identifiers, not the values of identifiers with identical names in the external block.
Example:
void OnStart() |
Local variables declared as static have the scope of the block, despite the fact that they exist since the program start.
See also
Data Types, Encapsulation and Extensibility of Types,Initialization of Variables, Visibility Scope and Lifetime of Variables, Creating and Deleting Objects
© 2000-2010, MetaQuotes Software Corp.