Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Scope of variable


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Scope of variable

  1. 1. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  2. 2. Scope of variables Jaseena A P Muhammed A P me 9539443588
  3. 3. WHAT IS A VARIABLE? In computer programming, a variable is a storage location and an associated symbolic name (an identifier) which contains some known or unknown quantity or information, a value.  The variable name is the usual way to reference the stored value; this separation of name and content allows the name to be used independently of the exact information it represents.
  4. 4. WHAT IS SCOPE?  The part of a computer program where the identifier, can be used to find the referred entity. Scoping rules are crucial in modular programming, so a change in one part of the program does not break an unrelated part.
  5. 5. SCOPE (CONTD…) Lexical Dynamic Scope Local Global
  6. 6. SCOPE (CONTD…)  In lexical scoping (or lexical scope; also called static scoping or static scope), if a variable name's scope is a certain function, then its scope is the program text of the function definition.  In dynamic scoping (or dynamic scope), if a variable name's scope is a certain function, then its scope is the time-period during which the function is executing.
  7. 7. LEVELS OF SCOPE  Expression scope  Block scope  Function scope  Module scope  File/Global scope Local scope Global scope
  8. 8. LEVELS OF SCOPE(contd…)  Expression scope: A declaration's scope is a single expression. eg:-int sum(int a,int b);  Block scope: scope is restricted to a block. Eg:-char a; switch(a) { case y: //do something case n: //do something }
  9. 9. LEVELS OF SCOPE(contd…)  Function scope: Scope of the variable is restricted to the body of the function which declared it. void sum(int a,int b) { int c;// c is alive inside sum() only. } void main() { int sm;//sm is alive in main() only }
  10. 10.  Module scope: In modular programming, the scope of a name can be an entire module, however it may be structured across various files. Eg:- Python  Global/File scope: A declaration has global scope if it has effect throughout an entire program. Variable names with global scope are frequently considered bad practice due to the possibility of name collisions. LEVELS OF SCOPE(contd..)
  11. 11. LEVELS OF SCOPE(contd…) Example for global(global/file scope) variable int year = 1994; // global variable int Max (int, int); // global function int main (void) // global function { //... }
  12. 12. Local vs Global scope int xyz; // xyz is global void Foo (int xyz) // xyz is local to the body of Foo { if (xyz > 0) { double xyz; // xyz is local to this block //... } }
  13. 13. THANK YOU
  14. 14. If this presentation helped you, please visit our page and like it. Thanks in advance. | |
  15. 15. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: