What do you understand by local and global scope of variables? How can you access a global
Variable inside the function, if function has a variable with same name
Answers
Answered by
14
Answer:
Global variables are declared outside any function, and they can be accessed (used) on any function in the program. Local variables are declared inside a function, and can be used only inside that function. It is possible to have local variables with the same name in different functions.
Answered by
8
Answer:
Difference between local and global variable...
KEY DIFFERENCE
- Local variable is declared inside a function whereas Global variable is declared outside the function.Local variables are created when the function has started execution and is lost when the function terminates, on the other hand, Global variable is created as execution starts and is lost when the program ends.Local variable doesn’t provide data sharing whereas Global variable provides data sharing.Local variables are stored on the stack whereas the Global variable are stored on a fixed location decided by the compiler.Parameters passing is required for local variables whereas it is not necessary for a global variable.
Hope it helps you....
Similar questions