August 2012
Intermediate to advanced
976 pages
30h 17m
English
constAs with references, we can define pointers that point to either const or nonconst types. Like a reference to const, a pointer to const (§ 2.4.1, p. 61) may not be used to change the object to which the pointer points. We may store the address of a const object only in a pointer to const:
const double pi = 3.14; // pi is const; its value may not be changeddouble *ptr = π // error: ptr is a plain pointerconst double *cptr = π // ok: cptr may point to a double that is const*cptr = 42; // error: cannot assign to *cptr
In § 2.3.2 (p. 52) we noted that there are two exceptions to the rule that ...
Read now
Unlock full access