C + +:: domain operator
Scope: The extent to which variables function in a program
Simple: global scope, local scope, statement scope
Scope Priority: the smaller the scope, the higher the priority
Scope operator:"::"
If you want to use global variables of the same name within the scope of a local variable, you can precede the variable with ":: ","::" called the scope operator.
- //scope
- #include <iostream>
- using namespace Std;
- int Avar=10; //global variable Avar
- int main()
- {
- int Avar=20; //local variable Avar
- cout<<"Avar is:"<<avar<<endl; //access local variables
- Avar=25; //1 //modify local variables
- cout<<"Avar is:"<<avar<<endl;
- cout<<"Avar is:"<<:: Avar<<endl; //Access global variables
- :: Avar=30; //2 //Modify global variables
- cout<<"Avar is:"<<:: Avar<<endl;
- return 0;
- }
Output
- Avar is:20
- Avar is:25
- Avar is:10
- Avar is:30
C + +:: domain operator