a variable that has meaning only within a particular function, subroutine, or other program unit.The name of a local variable can be used in another subroutine elsewhere in the program, where it will refer to an entirely different variable. Local variables contrast with global variables, which are recognized throughout the program.
The advantage of using local variables is not obvious in short programs. However, it is a good idea when writing a long program to make as many variables as possible local, because then there will be no problem if you wish to use the same name to mean something else elsewhere in the program. This rule is even more important if several different people are writing subroutines that will be combined into one main program.