Static Scope and Dynamic Structure
Static scoping decides the declaration of a name by examining the program text only. Pascal and C are few languages that use static scoping.
The blocks in the program help to find out the scope of a variable.
Example:
void main() { int x=1, y=2, sum; { Int x=2,add; { add=y+b; } //Block A sum= x+y; } //Block B } //Block C |
In the above example program. The scope of the variable ‘add’ is only until Block A, the scope of variable ‘sum’ is in Block B and the scope of variables x and y are in Block C.
We also see that the value of x varies in two different blocks. Here, the scope of x with value 2 is only in block A, whereas, the scope of x with value 1 is global, or scope is in block C.
Reference Link