A type of variable which is defined in a procedure or module and not accessible to any other module. The variables that have scope only inside the module are called local variables.
A type of variable which is defined in a procedure or module and accessible to all the modules in the program. The variables that have scope outside the module are called global variables.
A program to show local and global variables are:
DECLARE FUNCTION PRODUCT(A, B)
CLS
INPUT"ENTER TWO NUMBERS:'; A, B
PRINT"THE PRODUCT:"; PRODUCT (A, B)
END
FUNCTION PRODUCT (A, B)
P = A * B
PRODUCT = P
END FUNCTION
Here A and B are global variables as they are defined in the main module and are accessed by the submodule.
P is a local variable as it is used only by the function and cannot be accessed by the main module.