liveBook · Manning

File scope

As explained in Modern C, Third Edition

File scope is the scope of an identifier declared outside a function or block, extending through the relevant source file.

File scope is the scope of an identifier declared outside a function or block. In C, the name main has file scope because its declaration is not inside parentheses or braces. Identifiers with file scope are commonly called globals. section 2.2

Declarations outside a function

int main(int, char*[]); int argc; [[maybe_unused]] char* argv[]; double A[5]; size_t I; The declarations shown outside a function or block occupy file scope. A function body, a for construct, and its loop body introduce nested block scopes beneath file scope. section 2.2

int main(int, char*[]);
int argc;
[[maybe_unused]] char* argv[];
double A[5];
size_t I;

Inspect representative declarations placed at file scope, including main, variables, an array, and a size_t object. section 2.2

How Modern C, Third Edition covers it

How deep it goes
Defines file scope and contrasts it with nested block scope, stopping short of detailed linkage or lifetime rules.
Examples
Uses declarations of main, argc, argv, an array, and a size_t object as file-scope examples.
What you can do after
Evaluate whether a declaration belongs to file scope by checking whether it lies outside parentheses and braces.
How it connects
Connects file scope with block scope, nested scopes, identifiers, functions, and globals.

Also explained in

Compare how 2 books explain file scope →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.