A variable’s visibility describes the locations within a program from which it can be accessed. It can be referred to in statements in some parts of the program; but in others, attempts to access it lead to an unknown variable error message. The word scope is also used to describe visibility. The scope of a variable is that part of the program where the variable is visible.
- Automatic variables are only visible within the function in which they are defined. In the case of automatic variables, lifetime and visibility coincide: These variables exist only while the function in which they are defined is executing, and are only visible within that function.
- External Variables - While automatic variables are defined within functions, external variables are defined outside of (external to) any function. An external variable is visible to all the functions in a program.
- Static Variable - A static automatic variable has the visibility of a local variable Its lifetime is similar to that of an external variable, except that it doesn’t come into existence until the first call to the function containing it. Thereafter it remains in existence for the life of the program.

0 comments:
Post a Comment