- Global Variables: Variables declared outside a function or in a global space are called global variables. These variables can be accessed by any function in the program.
- Local Variables: Any variable declared inside a function is known as a local variable. This variable is present in the local space and not in the global space.
Shathana. S.R. Answered question July 7, 2023
In short, local variables are defined within a specific block or function and are only accessible within that scope. They have a limited lifespan and cannot be accessed from outside the scope. Global variables, on the other hand, are defined outside any function or block and can be accessed and modified from anywhere in the program. They have a longer lifespan but should be used with caution to avoid naming conflicts.
Riya Answered question July 7, 2023
