Saturday, November 8, 2014

2.10 LOCAL VARIABLE vs GLOBAL VARIABLE


 
LOCAL VARIABLE
GLOBAL VARIABLE
1
Variables declared within the function body are called local variables.
Variables declared outside of all the functions of a program and accessible by any of these functions are called global variables.
2
They are automatically created at the point of their declaration within the function body, and exist inside the specific function that creates them.
They are created at the beginning of program execution and remain in existence all through the period of the execution of the program.
3
They are unknown to other functions and to the main program.
These variables are known to all functions in the program and can be used by these functions as many times as may be required.
4
They are recreated each time a function is executed or called.
They do not get recreated if the function is recalled.
5
The existence of the local variables ends when the function completes its specific task and returns to the calling point.
Global variables do not cease to exist when control is transferred from a function. Their value is retained and is available to any other function that accesses them.

 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.