Identifiers and Scope
- Scope—the region of program code where it is legal to reference an identifier; also called scope of visibility or scope of access
- Three categories: local scope, global scope, and class scope; at this point, we only have local and global scopes
- Function names have global scope; once a function is declared (function declaration prototype), it can be used anywhere in the program
- Variables and constants can have global scope if they are declared before main
- Variables and constants declared within functions have local scopes; this is what we have been dealing with mostly
- Local identifiers with the same name as a global identifier have precedence within the function
- A block is defined as the region between a pair of curly braces
- Functions also include their parameters in the same scope as the function body, which is between curly braces (a block)
Previous page
Next page
Back to Lesson 6 Index
Back to Outline