The scope is also determined by the lifetime, orextent, of the variable. We explored the lifetime of variables and memory in Chapter 17, UnderstandingMemory Allocation and Lifetime. We revisit this topic here since it relates to the other components of scope: visibility and linkage.
The extent of a variable begins when a variable is created (memory is allocated for it) and ends when the variable is deallocated or destroyed. Within that extent, a variable is accessible and modifiable. Attempting to access or modify a variable outside of its extent will either raise a compiler error or may lead to unpredictable program behavior.
Internal variables have a somewhat limited extent, which begins within a block when the variable is declared and ends when the block ends. External variables are allocated when the program loads and exist until the program ends.
A variable's extent is also specified by a storage class, or how it is allocated...