C,const and pointers, position comparison table

Source: Internet
Author: User

A combination of const and pointers:

The comment section indicates illegal.

    intA =1; Const int*p =0; P=&A; //*p = 1;    int Const*PP =0; PP= &A; //*pp = 1;    int*ConstPV =0; //pv=&a;*PV =1; Const int Const*PAVP =0; //PAVP = &a; //*PAVP = 1;     Const int*ConstPBVP =0; //PBVP = &a; //*PBVP = 1;    int Const*ConstPCVP =0 ; //PCVP = &a; //*PCVP = 1;

The following code can be a key: because C + + has no const* operator, Const can only belong to the preceding type.

    int a =1;     int* int_ptr;     Const INT_PTR p=0;     // p=&a;    1 ;     Const pa=0;     // pa=&a;    1;

When const is placed at the top, only the right combination is selected.

The const int *P indicates that int is immutable, *p is a const.

int* Const p indicates that the pointer p cannot be changed, but its *p is mutable.

C,const and pointers, position comparison table

Related Article

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.