When a variable (or constant) declaration
is made, the computer reserves
space in memory for storing its value.
The scope of a variable
(or constant) is the section of program where a variable's value
may be accessed and used.
Global variables exist throughout the run of a program.
They are declared at the start of a program and values may be
accessed at any time during the run of the program.
Local variables are declared in a subroutine. They are created when the subroutine is started
and only exist for the time the subroutine is run. When the
subroutine is completed the memory space reserved for local
variables is released for other use.
Note : It is important that variables and constants
should be declared locally if possible. This saves memory space
when programs are run.
|