The visibility of a variable is largely determined by its location within a source file. There are a number of places a variable can appear, which determines its visibility. Some of these we have already explored. The following is a comprehensive listing of types of visibility:
- Block/local scope: This occurs in function blocks, conditional statement blocks, loop statement-body blocks, and unnamed blocks. These are also called internal variables. The visibility of variables declared in this scope is limited to the boundaries of the block where they are declared.
- Function parameter scope: Even though this scope occurs in function parameters, the function parameters are actually within the block scope of the function body.
- File scope: These are also called external variables. A variable declared outside any function parameter or block is visible to all other functions and blocks in that file.
- Global scope: When...