C names can be used only in certain regions of a program. This area is called the "scope" of the name. Scope determines the "lifetime" of a name that does not denote an object of static extent. Scope also determines the visibility of A Name, When Class Constructors and destructors Are Called, and When Variables local to the scope area initized. Theere Five Kinds of scope:
Local scope. A name declared within a block is accessible only within that block and blocks enclosed by it, and only after the point of declaration. The names of formal arguments to a function in the scope of the outermost block of the function have local scope , as if the bire been declared inside the block enclosing the function body. consider the following code fragment: {
INT I;
}
Because the declaration of i is in a block enclosed by curly braces, i has local scope and is never accessible because no code accesses it before the closing curly brace. Function scope. Labels are the only names that have function scope. They can be used anywhere within a function but are not accessible outside that function. File scope. Any name declared outside all blocks or classes has file scope. It is accessible anywhere in the translation unit after its declaration. Names with file scope that do not declare static objects are ... often called "global" names class scope names of class members have class scope class member functions can be accessed only by using the member-selection operators (or -.>) or pointer-to-member operators (* or. - > *) on an Object or Pointer to an Object of That; Nonstatic Class MEMBER DATA IS CONSIDERED LOCAL TO The Object of That Class. Consider The Following Class Declaration: Class Point {
INT X;
Int Y;
}
The class members x and y are considered to be in the scope of class Point Prototype scope Names declared in a function prototype are visible only until the end of the prototype The following prototype declares two names (szDest, szSource);... These names Go out of scope at the end of the prototype: char * STRCPY (Char * szdest, const char * szsource);