2. A variable declared within a sub-program (procedure or
function) is known as a local variable and has local
scope
It is only recognised within the sub-program in which it
has been declared
The variable can only be changed by code within that
sub-program
Local Variable
3. A variable declared as global in the main program has
global scope
It can be recognised and changed across the entire
program
This might not be an issue in smaller programs, but can
be a problem in larger programs.
WHY?
Global Variable
5. Are Global Variables Bad?
Generally speaking, global variables are considered bad,
especially in larger programs.
If you declare a global variable, it’s harder to keep a track
on what changes are made to it across different parts of
the program. It makes it difficult to debug errors.
6. Are Global Variables Bad?
Generally speaking, global variables are considered bad,
especially in larger programs.
If you declare a global variable, it’s harder to keep a track
on what changes are made to it across different parts of
the program. It makes it difficult to debug errors.