"C + +" Judging the effect of the different positions of const affixes

Source: Internet
Author: User

Eg: q (1) const char *P

(2) What is the difference between char * const P?

Method: The const is regarded as an adjective affix, that is, next to the nearest noun.

If there is * to note, * means a pointer to the type XX, the combination variable name is a noun.

Explain that the above affixes are (1) A pointer to a constant char type (the value pointed to by the pointer cannot be changed and the pointer can point to another value)

(2) A pointer to a char type, constant (the value that the pointer points to can be changed, and the pointer cannot point to another value)

Note the difference between char * const P and Char const * p,

Part-of-speech analysis: char nouns, * nouns, const adjectives, p nouns

char * const P is equivalent to char (* const p), const belongs to the affix of * p, that is, by adding a boundary line between *p, then P is unchanged, *p can be changed.

While Char const *P is relative to (char const) (*p), const belongs to char, then P is changed, and *p is unchanged.

"C + +" Judging the effect of the different positions of const affixes

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.