Const char * P, char const * P, and char * const P

Source: Internet
Author: User

Const char * P and char const * P are modified by * P, so the content pointed to by P pointer will not change.

The const of char * const P modifies the P variable, so the point of P cannot be changed, and the address of the P record remains unchanged, but the content stored on the address can be modified, for more information, seeProgram:


# Include <iostream> <br/> using namespace STD; </P> <p> void main () <br/>{< br/> char * A = "ABC"; <br/> char * B = "BCD "; </P> <p> const char * P = A; <br/> cout <p <Endl; <br/> P = B; <br/> // A = "BCD"; yes, but the P output is still "ABC" <br/> cout <p <Endl; </P> <p> char const * PP = A; <br/> cout <pp <Endl; <br/> PP = B; <br/> // A = "BCD"; yes, but the P output is still "ABC" <br/> cout <pp <Endl; </P> <p> char * const PPP = A; // must be initialized <br/> cout <PPP <Endl; <br/> A = "BCD "; <br/> // PPP = B; cannot run <br/> cout <PPP <Endl; <br/>}

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: 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.