Scope of Identifier Visibility in C

An identifier becomes visible with its declaration. The region where an identifier is visible is referred to as the identifier's scope.

The scope of an identifier is determined by where the identifier is declared. The four kinds of scope and their descriptions are:

Block Scope The identifier's declaration is located inside a statement block.

A block starts with an opening brace ({) and ends with a closing brace (}). An identifier with block scope is visible between the point where it is declared and the closing brace that ends the block.

Block scope is sometimes referred to as local scope.

Function Scope The only identifier with function scope is a label name.

A label is implicitly declared by its appearance in the program source. A goto statement transfers control to the label specified in the goto statement. The label is visible to any goto statement that appears in the same function as the label.

File Scope The identifier's declaration appears outside any block.

It is visible from the point where it is declared to the end of the source file. If the source files are included by #include preprocessor directives, those files are considered to be part of the source, and the identifier will be visible to all included files that appear after the declaration of the identifier.

The identifier can be declared again as a block scope variable. The new declaration replaces the file-scope declaration until the end of the block.

Function Prototype Scope The identifier's declaration appears within the list of parameters in a function prototype.

It is visible from the point where it is declared to the closing parenthesis of the prototype declaration.

 



Program Linkage Between Identifiers
Storage Duration
Name Spaces
Identifiers