+ 3
What is the difference between global and local variable?
Please give a answer..
7 Réponses
+ 3
A local variable is declared inside any function.
Local variable are stored on the stack unless specified.
A global variable is declared outside any function.
Stored on a fixed location decided by a compiler.
+ 4
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.
+ 4
A local variable is destroyed when the control of the program exit out of the block in which local variable is declared. However, a global variable is destroyed when the entire program is terminated.
+ 3
Check out the link
https://funprogramming.org/50-What-are-global-and-local-variables.html
+ 2
global variable is declared in outside of function it has file scope we can use it anywhere in program
local variable is declared under the function and it has block scope
+ 1
It's as simple as you spend one minute watching what's app message.
The name itself reflecting global variable means available for inside as well as outside every scope i.e. for, while,if else etc. in the program.Whereas, local is limited to Personal scope i.e only in for, while etc. Outside use is forbidden. :-) like if you find interesting.
+ 1
Java doesn't have traditional global variables, just static on classes, which are still technically not global