The technique of distinguishing the const pointer type in C + +

Source: Internet
Author: User

Constants (Constant)

The const variable in C + + must be assigned an initial value when defined. The const pointer also needs to assign an initial value.

Const binding pointer * There are three common types:

1, const int* A; A is a pointer to a long integer, the integer cannot be modified, but the pointer can be modified. The value you are pointing to is a constant.


2, int* const A; A is a constant pointer to an integer, and the number of points can be modified by I, but the pointer cannot be modified. The address value is a pointer to a constant.


3, const int *CONST A; A is a constant pointer to a constant integer number, and the pointer and the number of digits it points to cannot be modified.


Classification tip: X is the base (bounds), X left and x right two parts. The right side of X indicates what type of variable is itself, and the left side of X indicates what type the pointer is pointing to.


For example 1 This explains: (this pointer is to a variable of const int, so a cannot be modified, but the pointer can be modified).

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.