External Variables:
External
identifiers such as global variables and function names are declared with
static storage duration
Global
variables and function names are of storage class extern by default.
Global
variables are created by placing variable declarations outside any function
definition, and they retain their values throughout the execution of the
program.
Global
variables and functions can be referenced by any function that follows their
declarations or definitions in the file.
In the ‘C’ program structure shown on the screen long value1 and int value4 are external variables.
Example:
#include<stdio.h>
#include<conio.h>
int
v=10;
void
main()
{
call1();
call2();
printf(“\n
in main() V=%d”,v);
}
call1()
{
printf(“\n
in call1() V=%d”,v);
}
call2()
{
printf(“\n
in call2() V=%d”,v);
}
OUTPUT
In
call1() V=10
In
call2() V=10
In
main() V=10
Explanation:
In
this program variable ‘v’ is declared outside the function body and initialized
to value 10. Evert function can access the variable ‘v’ so no re-declaration or
local variable is created. Every function in turn prints the value of ‘v’. The
same value is printed by all the functions.