Scope and Local Variables
- In general a block of code is code within { }
- Variables declared within a block of code are local to that
block.
- The lifetime of a variable is the time it has memory
allocated to it.
- All variables we have been dealing with are automatic
variables. These variables are allocated at block entry and dealocated
when the block exits.
- Static variables are variables that persist over invoctions
of a block.
- The scope of a variable is the reagon of code where it is leagle
reference that variable.
- A nonlocal identifier is in identifier that is declared outside of the
scope of a block
- Some Rules
- Functions have global scope .. they can be used anywhere after they
are declared
- Function parameters have scope in the outermost block of the function
- Scope of global variables or constants is for the entire program
- Scope of local variables extens over the block in which it
is declared
- Local variables take persidence over global variables
- DO NOT USE GLOBAL VARIABLES.