Disadvantage of using Global Variable
- All the global variable that is declared inside the program remains in the memory till execution gets completed. This may cause Out of Memory issues.
- Modification of data is easy, it can be easily modified by any task or function. This can produce undesirable results in multi-tasking environments.
- Discontinuation of global variable due to refactoring will cause the problem of changing all the associated modules.
Let’s see some example to understand the global and local variables better.
Batch Script – Local VS Global Variables
In this article, we will see the differences between local and global variables in bash scripting.
Variable: The name given to a memory location that is used to store values in a program is called variables. It stores information that can be called and manipulated wherever needed in the program.
Scope: The part or extent of the program where the variable is accessible or said to be alive.
Based on the scope of the variable, it is of two types:
Local variable: those variables whose scope is within the function where it is declared( can be accessed within the declared block or function in the program)
Global variable: these variables can be accessed globally in the entire program.