- The scope of a name is the part of the program within which the name can be used
- For an automatic variable declared at the beginning of a function, the scope is the function in which the name is declared. Local variables of the same name in different functions are unrelated
- The scope of an external variable or a function lasts from the point at which it is declared to the end of the file being compiled
- It is important to distinguish between the declaration of an external variable and its definition
- A declaration announces the properties of an external variable (primarily its type) (ie. extern int a;)
- A definition also cause storage to be set aside (ie. int a;)
- Array size must be specified with the definition, but are optional with an extern declaration
- Initialization of an external variable goes only with the definition
- Example:
Tuesday, March 22, 2011
4.4 Scope Rules
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment