Scope of the variable is defined as the area in the program where variable is callable.
In C language scope of variable depends on the type of variable like :
1. local variable
2. global variable
Local variable:
-In case of local variable, scope is limited upto that body or function in which variable was defined.
-You can not call the variable after the function body.
Global variable:
-In case of global variable, scope is increased
-and we can excess that variable anywhere in the program.
program-
#include< stdio.h>
int a=10;
void func()
{
printf("%d",a);
//printf("%d",i); it will give an error
}
int main()
{
int i=1;
printf("%d\n",a);
printf("%d\n",i);
func();
return 0;
}
10
1
10