############## External File to Import with Original Variable (var) Definition #########
filename: my_variable.c
int var = 22;
################ Calling Main Function ####################3
filename: main.c
#include
/* After importing the external variables file Compilation will work*/
#include "my_variable.c"
/**
* Extern keyword means that
* during linking the compiler will scan through
* all other c-file and locate a defined variable
* "int var =
* and incorporated to this main function
*/
extern int var;
int main(int argc, char **argv, char **envp)
{
printf("Original value is %d\n",var);
var = 10;
printf("Updated value is %d\n",var);
return (0);
}
/* Compiling this program will fail because the var variable is not defined
* anywhere in the program*/
/**
######## Compiling the Program #############333
$ gcc main.c -o a.out
$ ./a.out
# program Output #
Original value is 22
Updated value is 10