Usage Analysis of pointer and const qualifier

Source: Internet
Author: User

constThere are several common cases of delimiter and pointer combination.

(1) pointer to a constant

const int *a; int const *a;

These two methods are the same,aIs a pointconst intType pointer,aThe memory unit cannot be rewritten, so(*a)++Is not allowed,aCan be rewritten, soa++Yes.

The content pointed to by the pointer remains unchanged, but the pointer itself can be changed.

(2) constant pointer

int * const a;

aIs a pointintTypeconstPointer,*aYes,aRewriting is not allowed.

The pointer itself cannot be changed, but the content pointed to by the pointer can be changed.

(3) constant pointer to a constant

int const * const a;

aIs a pointconst intTypeconstPointer, so*aAndaCannot be rewritten.

The pointer itself and the content to which it points cannot be changed.

In the above three cases, if you want to learn c ++, You should have contact!

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.