The extern keyword is used in C language to declare externally defined variables, functions or other symbols to avoid repeated definition errors and enhance code scalability. It allows an external symbol to be declared, allocated memory and referenced in the current source file even if it is not exactly defined.
The role of extern keyword in C language
extern keyword is C A key keyword in the language used to declare that a variable, function, or other symbol is defined outside the current source file.
Function:
Syntax:
<code class="c">extern [类型] [符号名];</code>
Usage scenarios:
extern keyword is often used in the following scenarios:Example:
<code class="c">// 定义一个名为"x"的变量,并将其存储在外部源文件中 extern int x; // 在当前源文件中声明该变量 // 使用定义在其他源文件中的"f"函数 extern void f();</code>
The above is the detailed content of The role of extern in c language. For more information, please follow other related articles on the PHP Chinese website!