Scope - Static and Dynamic

11,763 views
10,963 views

Published on

This presentation is about scope and its types as static and dynamic.

Published in: Education, Technology, Business
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
11,763
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
214
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Scope - Static and Dynamic

  1. 1. PRINCIPLE OFPROGRAMMING LANGUAGES SCOPESTATIC AND DYNAMIC SNEH PAHILWANI SYMBIOSIS INSTITUTE OF TECHNOLOGY
  2. 2. In computer programming, a scope is thecontext within a computer program in whicha variable name or other identifier is valid andcan be used, or within whicha declaration has effect.Outside of the scope of a variable name,the variables value may still be stored, andmay even be accessible in some way, but thename does not refer to it; that is, the name isnot bound to the variables storage.
  3. 3. SCOPESTATIC DYNAMIC
  4. 4.  Also called lexical scoping. If a variable names scope is a certain function, then its scope is the program text of the function definition: within that text, the variable name exists, and is bound to its variable, but outside that text, the variable name does not exist.
  5. 5. Output:23•Encounter occurrence of„x‟.•Search local blockvariables•If not there, keepsearching in parent blocks.•If not there too, in globalscope then.•Otherwise „error‟
  6. 6. SCOPESTATIC DYNAMIC
  7. 7.  In dynamic scoping (or dynamic scope), if a variable names scope is a certain function, then its scope is the time-period during which the function is executing. While the function is running, the variable name exists, and is bound to its variable, but after the function returns, the variable name does not exist.
  8. 8. Pointing the difference out•Under static scoping: prints out22•Under dynamic scoping: prints out34•At “runtime” one searches forthe declaration•Search in local variables•If not found, search in localvariables of the caller•If not found, search in globalvariables•Otherwise error
  9. 9. www.wikipedia.orghttp://cseweb.ucsd.edu/cl asses/sp05/cse130/lecture_ notes/scoping_student.txt

×