Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
589
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
8
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 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. Scope of variables Jaseena A P jsnp65@gmail.com www.facebook.com/Jaseena Muhammed A P twitter.com/username in.linkedin.com/in/profilena me 9539443588
  • 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. 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. SCOPE (CONTD…) Lexical Dynamic Scope Local Global
  • 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. LEVELS OF SCOPE  Expression scope  Block scope  Function scope  Module scope  File/Global scope Local scope Global scope
  • 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. 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.  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. 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. 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. THANK YOU
  • 14. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 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: info@baabtra.com