Site icon i2tutorials

Compiler Design-Scope Management

Scope Management

 

The region in which the accessibility of a variable is called scope.

It is divided into 2 types:

  1. Local Scope
  2. Global Scope

 

LOCAL SCOPE:

The scope in which the validity of a variable or accessibility of a variable within function or sub-function is called local scope.

Example:

fun()
{
   Int a, b;
   Float f;
}

GLOBAL SCOPE:

The accessibility of a variable or lifetime of a variable throughout the program such as it can be accessed anywhere in the program of functions and sub-functions of the program 

 

Example:

Int x=10;
Void main()
{
      x = x+1;     (10+1=11)
      fun(void)
      printf(“%d value of x is %d”, x);   (61)
}

Void fun()
{
      x= x+50;    (11+50)
      printf(“x value in fun is %d”, x);    (61)
}


Reference Link

Scope Management

Exit mobile version