tailieunhanh - Lecture Practical C++ programming - Chapter 9: Variable scope and functions

Chapter 9 introduce students to local variables. First familiarize the students with the concepts of when variables are created and destroyed. This will prepare them for classes where variable creation and destruction my result in a function call. This chapter also introduce the tricky subject of recursion. | Chapter - 9 Variable Scope and Functions Practical C Programming Copyright 2003 O Reilly and Associates Page 1 Variable Scope and Class Variables are defined by two attributes Scope The area where a variable is valid Local or Global Storage Class Describes the storage allocation of the variable Permanent or Temporary Practical C Programming Copyright 2003 O Reilly and Associates Page 2 Variable Scope Global variables are valid everywhere. Local variables are only valid inside the where they are defined. Scopiof globa Ậ a global variable int main 4nt locaA 1 Scope of local global 1 local 2 Scionpte voefr eginning a new block a local variable global can be used here so can local this is local to the block global local very_locaal L Block closed very_local can not be used return 0 Practical C Programming Copyright 2003 O Reilly and Associates Page