Suppose a program is divided into three files f1, f2 and f3, and a variable is defined in the file f1 but used in files f2 and f3. In such a case would we need the extern declaration for the variables in the files f2 and f3?
variable f1 in FILE1.C
variable f2 in FILE2.C
variable f3 in FILE3.C
If we need to use the variable f1 in the files FILE2.C and FILE3.C
We have to declare the variable f1 as extern int f1; in the files FILE2.C and FILE3.C.
The only way this can be achieved is to define the variable locally in main() instead of defining it globally and then passing it to the functions which need it.