Recent Post

Scope and Binding

 Scope of a program variable is the range of statement in which the variable is visible. A variable is visible in a statement if it can be referenced in that statement.

Static Scoping:- 

  The method of binding names to non local variable called static scoping.
Scope of variable can be statically determined prior to execution.
Easier to read , more reliable , and executes faster.

Dynamic Scoping:-

   It is based on the calling sequence of subprograms.
Scope can be determined at run-time.
More flexibility, but expense of readability,reliability and efficiency.

Example: Consider following program with function calls.

Static scope for the above program :-

Dynamic scope for the above program :-


        Binding is the association of attributes with program entities.
It can take place at language design time ,language implementation time , compiler time ,link time , load time or run-time.
A binding is static , if it occurs before run-time and remains unchanged throughout execution.
A binding is dynamic , if it occurs during run-time or can change in the course of program execution.

1 comment: