+ 11
"Global" and "Local" Variables
Whatâs the defferent between Global variables and Local ones? I heard that using Local variables is faster than using Global ones. Places they are saved are different?
11 Answers
+ 21
A global variable is avaliable throughout the whole code.
A local variable is only avaliable in the function that it is in.
+ 5
In "func" block, if it outputs a ,then "local" is displayed, right?
+ 5
Marat Khudaiberdin did you mean var a instead of car a?
+ 4
OK. I see.
Iâ ll be careful about the lifespans of variables !
+ 4
A global variable is accessible from anywhere in the code (in any blocks). And the local variable has a local scope, means it is only accessible in the code block where it is declared. But languages has different methods to declare a global variable from a local scope.
+ 4
This code from a C quiz question is a good example of global and local variables both of the same name i
https://code.sololearn.com/cp4Z6UtRgH2z/?ref=app
+ 3
Oh, PHP has such a defferent rule? There are various features among the languages...
+ 3
Wow! I didnât know that.
+ 2
You can cite to global variables anywhere in your code (except for PHP)
+ 1
One doubt. Should we have to save a file called someexample.php...what should that file contain
+ 1
Global belongs to whole code but local is belongs toy present In the {} function