In: Computer Science
1. Briefly describe the four categories of identifier scope in C++.
2. List the three steps in loop design.
**please give simple answers. I don't need a code. Just the definitions please.
Every identifier has a scope that is determined by where it is declared. Identifier Scope in a program is the region(s) of the program within which the identifier can be used. Using a name outside of its scope is an error.
There are five possible scopes in C++: -
1. Block scope:
An identifier declared inside curly braces or in a function parameter list has block scope. Block scope extends from the declaration to the enclosing right brace.
2. Function scope: Labels in C/C++ have their own scope. They are accessible before and after their declaration, for the whole function. The thing that makes its scope unique is that the label (the declaration) can appear after the first goto that uses it
3. Class scope:
An identifier that is declared inside a class definition has class scope. Class scope is anywhere in the class definition or in the bodies of member functions.
4. File scope:
This is basically the same as global scope, except that file scope variables are not exported to the linker. The keyword static hides an identifier from other source files and gives it file scope. File scope variables cannot be declared extern and accessed from another file. File scope variables, because they are not exported, do not pollute the global namespace. They are often used in C programs because C has no concept of private class members.
5. Global scope:
An identifier whose declaration is not in between braces (round or curly) has global scope. The scope of such an identifier begins at the declaration and extends from there to the bottom of the source code file.
Three steps in loop design are: -
1. Initialize: - Used to initialize the loop control variable.
2. Test: - Used to check the terminating condition for the loop.
3. Update: - It is used to update the loop control variable.
Loop also has a body which contains all the statements which are to be executed when the loop is executed.