C++:const Qualifier

Source: Internet
Author: User

Initialize:The Const object must be initialized once its value cannot be changed once it is created.

scope: The default const object is valid only within a file. Exception:extern const

constant Reference: the object that is bound cannot be modified by this reference.

int i=5; int &r1=i; Const int &r2=i;r1=1;    // correct, you can modify the value    of the bound object by reference r2=0;    // error, cannot modify the value of the bound object through a constant reference

Pointers and Const:

    • *CONST constant Pointer : Defines the pointer itself as a constant
      • The invariant is the value of the pointer itself, not the value of the constant being pointed to.
    • const* Pointer to constant:
    • Const *const A constant pointer to a constant object:

C++:const Qualifier

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.