/* */ Click to Join Live Class with Shankar sir Call 9798158723

Scope Rules in C ?


The External objects may be external variables or external function. The external variables are the variables that are defined outside any function they are available to all function. The function in c are always external function. Scope of an object is defined as the region or a boundary of the program in which an object is visible . Object can be variable of function prototypes.


Types of scope rules:-

  1. Global Scope.
  2. Local Scope.


Scope Rules and explaination

Scope of function Explaination
int sum() Function prototype, Global Scope, It can be call anywhere within a program
int a,b; Global Scope, It can be use anywhere within a program.
void main()
{
int x,y;
}
Local scope or local variable. It can be use only in this function. Out of this function can not scope so it give a error of variable declaration.
sum()
{
s=x+y;
su=a+b;
}
x and y not declare in this function it declare on main function so give a error.x y has scope only in main()function. A and B are global variable so it can be call in any function.

Note: C does not allow function to be defined inside other function means nested function does not allow.