Complete Computer Knowledge Portal

Saturday, March 30, 2013

Difference Between Local and Global Variables

Sr. No.
Local Variable
Global Variable
1
Local variables are those variables which are accessible inside the specific function that creates them.
Global Variables are those variables that can be accessed by any function comprising the program.
2
They are normally implemented using a stack.
They are implemented by associating memory locations with variable names.
3
They are recreated each time a function is executed or called.
They do not get recreated if the function is recalled.
4
The lifetime or scope of a local variable is just within a procedure or a block
The scope of a global variable is throughout the program.
5
It makes easy debugging and maintenance of applications.
In the case of global variables, one cannot be sure in which function it will be modified or when the variable values will be modified.

No comments:

Post a Comment