Constant pointers and pointers to constants

Source: Internet
Author: User

3 Scenarios related to the const, pointer, and object pointed to by the pointer:

1. Pointers to constant objects

2. Constant pointer to an object

3. Constant pointers to constant objects

In the first case, we cannot modify the object being pointed to, but we can point the pointer to another object:

Const char* pstring ("Some text");

In the second case, we cannot modify the address stored in the pointer, but you can modify the object that the pointer points to:

char* Const pstring ("Some text");

In the last case, both the pointer and the object being pointed to are defined as constants and therefore cannot be modified:

Const char* Const pstring ("Some text");

Constant pointers and pointers to constants

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.