Constant pointers and pointer constants in C + +

Source: Internet
Author: User


  • c++11 Use nullptr keyword is a null pointer that expresses a more accurate, type-safe

    Pointer to constant
      • You cannot change the value of a pointed object by a pointer to a constant, but the pointer itself can be changed to point to another object.

      • Cases

    int A;

    const int *p1 = &a; P1 is a pointer to a constant

    int b;

    P1 = &b;//correct,P1the value of itself can be changed

    * P1 = 1;// compile-time error, cannot passP1change the object you are referring to

    Constants for pointer types

    int A;

    int * Const P2 = &a;

    P2 = &b; Error,p2 is a pointer constant, the value cannot be changed


Constant pointers and pointer constants in C + +

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.