refers to where variables is declared.
It can be Inside a function or a block which is called local variables, In the definition of function parameters which is called formal parameters or Outside of all functions which is called global variables.
Global variables
Global variable are declared outside any functions, usually at top of program. they can be used by later blocks of code:
int g; //global
int main(void)
{
g = 0;
}
Local variables
Variables that are declared inside a function or block are local variables. The scope of local variables will be within the function only. These variables are declared within the function and can't be accessed outside the function.
void main()
{
int g; //local
g=2;
cout << g;
}
No comments:
Post a Comment