C + +:: domain operator

Source: Internet
Author: User

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.

  1. //scope
  2. #include <iostream>
  3. using namespace Std;
  4. int Avar=10; //global variable Avar
  5. int main()
  6. {
  7. int Avar=20; //local variable Avar
  8. cout<<"Avar is:"<<avar<<endl; //access local variables
  9. Avar=25; //1 //modify local variables
  10. cout<<"Avar is:"<<avar<<endl;
  11. cout<<"Avar is:"<<:: Avar<<endl; //Access global variables
  12. :: Avar=30; //2 //Modify global variables
  13. cout<<"Avar is:"<<:: Avar<<endl;
  14. return 0;
  15. }
Output
    1. Avar is:20
    2. Avar is:25
    3. Avar is:10
    4. Avar is:30

C + +:: domain operator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.