All variables defined within an external subprogram exist only in that subprogram. In other words, the scope of a variable in an external subprogram is confined to the subprogram in which it is defined.
The limited scope of variables provides another benefit to
programmers: it allows the programmer to reuse variable names
in different subprograms. For example, in the Fortran
example program above with the power function,
both the main program and the function have a variable called
exponent
. The x
in the
main program and the example
in the function
are different variables, i.e. they
represent different memory locations, and can therefore
contain separate values. Another way of saying this is that
each subprogram has its own name space.
The names of variables in one subprogram are kept separately
from the names of variables in other subprograms.