Following are the differences between a local variable and global variable:
Basis for comparison
A variable which is declared inside function or block is known as a local variable.
A variable which is declared outside function or block is known as a global variable.
The scope of a variable is available within a function in which they are declared.
The scope of a variable is available throughout the program.
Variables can be accessed only by those statements inside a function in which they are declared.
Any statement in the entire program can access variables.
Life of a variable is created when the function block is entered and destroyed on its exit.
Life of a variable exists until the program is executing.
Variables are stored in a stack unless specified.
The compiler decides the storage location of a variable
If you are a C++ programmer, it is important to understand the difference between call by value and call by reference. Call by value means that the value of the argument is copied into the parameter. Call by reference means that a reference to the argument is passed into the parameter.