Scope of variable means where the variable stands in the program. All variables may not necessary be available to all statements in a program.
Variables can have two types of scope:
a) Local:
When a variable is declared inside the function then such a variable is known as local variable.
A local variable can only be accessed by the function in which it is declared. It cannot be accessed by other function.
b) Global:
A variable which is declared outside all functions is known as global variable.
A variable with a global scope is accessible to all the statements in the program. A global variable can be accessed by all the functions.
0 comments:
Post a Comment