C 声明和定义C Declarations and Definitions

“声明”在特定变量、函数或类型及其特性之间建立关联。A "declaration" establishes an association between a particular variable, function, or type and its attributes. 声明概述declaration 非终止符提供了 ANSI 语法。Overview of Declarations gives the ANSI syntax for the declaration nonterminal. 声明还指定可访问标识符的位置和时间(标识符的“链接”)。A declaration also specifies where and when an identifier can be accessed (the "linkage" of an identifier). 有关链接的信息,请参阅生存期、可见性和链接See Lifetime, Scope, Visibility, and Linkage for information about linkage.

变量的“定义”将建立与声明建立的相同的关联,但也会导致为变量分配存储。A "definition" of a variable establishes the same associations as a declaration but also causes storage to be allocated for the variable.

例如,mainfindcount 函数以及 varval 变量在一个源文件中定义,顺序如下:For example, the main, find, and count functions and the var and val variables are defined in one source file, in this order:

int main() {}  

int var = 0;  
double val[MAXVAL];  
char find( fileptr ) {}  
int count( double f ) {}  

变量 varval 可用于 findcount 函数中;无需进一步声明。The variables var and val can be used in the find and count functions; no further declarations are needed. 但是,这些名称在 main 中不可见(无法访问)。But these names are not visible (cannot be accessed) in main.

请参阅See Also

源文件和源程序Source Files and Source Programs