C + + constant pointers and pointer constants

Source: Internet
Author: User

1. Constant pointer

Definition and use of pointer variables that point to constants

such as: const int *p;

2. Pointer constants

such as: char* const p = "ABCDE";

You can understand this:

The type char* of the const p, so p can not be modified. That is, the p must have been initialized at the time of definition and cannot be modified.

3. Pointer constants pointing to constants

Pointer constants pointing to constants

such as: const int* Const P = &b;

You can understand that.

int* the type of const P is const, then the int* const p is not modifiable.

And look at int* const p. The type of const p is int*, which is that p cannot be modified, and its type is int*.

Summarize:

No matter how the name of the pointer changes, it should be divided into a view. Start at the very beginning, layer by layer, and look at these names with the "Type-object" perspective.

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.