While coding, you'd like certain variables to be accessible (addressed) by any of the sub-routines and procedures you encode such "name" (received) so you'd need to define it as "global". Sub-routines, procedures that are required may take the info and manipulate it within the routine or only be valid to the routine itself, you'd need to define "locally"...this way, not to be exposed or alter any of the variables previously received or defined as global.
That said, a global variable are defined at the beginning of the program itself to be accessible to all routines and procedures; whereas a local variable is defined within the sub-routine or procedure itself.
2010-05-02 14:18:30 UTC
local ,Global variables are mainly involved with the scoop also there are Public, Private mainly two type of Variables type beside friend etc..
the variable scoop consider where that is Declared if you done in side of a Event or a Function of Scripts (VB JavaScript etc..) then it has been considered as Local Variable because it's only limited inside of that Function or event
in Programming
C#, Java ,C++
Global Variables
--------------------------
class className
{
int _variable_1 ;
string _variable_2 ;
double _variable_3 ;
char _variable_4 ;
bool _variable_5 ;
the Local variables
------------------------------
void methodName()
{
int _variable_1 ;
string _variable_2 ;
double _variable_3 ;
char _variable_4 ;
bool _variable_5 ;
}
}
in Scripting
if you declare a Local Variable you can access into that variable within that region only but if you declared a variable as global you can access that into all over the class
also if you declared it as public you can use that not only same class but also in entire program
else private only in that declared class
Elysion
2010-05-02 14:02:53 UTC
Local variables are variables that can only be accessed within a certain scope. An scope can be defined with {} for example.
Like this:
void foo(){
int bar;
bar++;
}
"bar" can only be accessed within the function "foo".
Global variables can be accessed by any kind of code. Generally, it is a bad practice to use them.
For example.
int var1;
int var2;
voif foo(){
}
int main(){
return 0;
}
var1 and var2 can be accessed by any block of code in the program.
?
2016-12-05 01:51:36 UTC
worldwide skill you ought to use it in any journey, interior of reach skill you are able to basically use it interior the form the place this is declared. occasion, C++: #comprise iostream utilising namespace std; bool x; //worldwide Boolean variable, could be used everywhere void attempt() { //x could be used here, yet y can not } int considerable(); { int y; //interior of reach y integer, can basically be used in this journey { VB6: Dim x as string 'worldwide x variable, because of the fact this is outdoors the activities inner maximum Sub Command1_Click() Dim y as integer 'interior of reach y variable, because of the fact this is interior an journey end Sub
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.