Saved Bookmarks
| 1. |
Explain scope of variable with example. |
|
Answer» Scope refers to the accessibility of a variable. There are four types of scopes in C++ 1. Local Scope 2. Function Scope 3. File Scope 4. Class Scope 1. Local Scope:
Example: int main( ) { int a,b; //Local variable } 2. Function Scope:
Example: int. sum(intx, int y); //x and y has function scope. 3. File Scope:
Example: #include using namespace std; int x,y; //x and y are global variable void main() { …….. 4. Class Scope:
Example: Class example { int x,y; //x and y can be accessed by print() and void(): void print(); Void total(); }; |
|