C++ Programming/Programming Languages/C++/Code/Keywords/extern

The   keyword tells the compiler that a variable is defined in another source module (outside of the current scope). The linker then finds this actual declaration and sets up the   variable to point to the correct location. Variables described by   statements will not have any space allocated for them, as they should be properly defined elsewhere. If a variable is declared extern, and the linker finds no actual declaration of it, it will throw an "Unresolved external symbol" error.

Examples:
 * : declares that there is a variable named i of type int, defined somewhere in the program.


 * : defines a variable j with external linkage; the   keyword is redundant here.


 * : declares that there is a function f taking no arguments and with no return value defined somewhere in the program;   is redundant, but sometimes considered good style.


 * : defines the function f declared above; again, the   keyword is technically redundant here as external linkage is default.


 * : defines a constant int k with value 1 and external linkage; extern is required because const variables have internal linkage by default.

  statements are frequently used to allow data to span the scope of multiple files.

When applied to function declarations, the additional "C" or "C++" string literal will change name mangling when compiling under the opposite language. That is,  allows C++ code to execute a C library function plain_c_func.