C + + array and pointer

Source: Internet
Author: User

Pointer to const object and const pointer,

1. A pointer to a constant object that means that the contents of the object pointed to by the pointer cannot be changed (cannot be assigned by pointer).

2. Constant pointer, meaning that the pointer content cannot be changed, pointing to object A cannot be changed to point to object B (pointers cannot be pointed elsewhere).
(Simply put, the const is near, which cannot change.) )

Pointer to const OBJECT:CONST double *cptr; Cptr is a constconst double pi = 3.14;double *ptr =π//error:ptr are a plain pointerconst do Uble *cptr =π//Ok:cptr is a pointer to constconst int universe = 42;const void *CPV = &universe; OK:CPV is constvoid *PV = &universe; Error:universe is constconst pointer:int errnumb = 0;int *const Curerr = &errNumb; Curerr is a constant pointercurerr = Curerr; Error:curerr is const

There's a more disgusting, const pointer to a const object

A constant pointer to a constant object, and a two (pointer and object) cannot be changed, both of which are const.

Const double PI = 3.14159;//pi_ptr is const and points to a const objectconst double *const pi_ptr =π

  

C + + array and pointer

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.