Extern stands for external storage class. Extern storage class is used when we have global functions or variables which are shared between two or more files.
Keyword extern is used to declaring a global variable or function in another file to provide the reference of variable or function which have been already defined in the original file.
The variables defined using an extern keyword are called as global variables. These variables are accessible throughout the program. Notice that the extern variable cannot be initialized it has already been defined in the original file.
Example, extern void display();
First File: main.c
#include <stdio.h> extern i; main() { printf("value of the external integer is = %d\n", i); return 0;}
Second File: original.c
#include <stdio.h> i=48;
Result:
value of the external integer is = 48
In order to compile and run the above code, follow the below steps
Step 1) Create new project,
- Select Console Application
- Click Go

Step 2) Select C and click Next

Step 3) Click Next

Step 4) Enter details and click Next

Step 5) Click Finish

Step 6) Put the main code as shown in the previous program in the main.c file and save it

Step 7) Create a new C file [File -> new -> Empty File , save (as original.c ) and add it to the current project by clicking “OK” in the dialogue box .

Step 8) Put and save the C code of the original.c file shown in the previous example without the main() function.

Step 9) Build and run your project. The result is shown in the next figure
