August 2001
Beginner
482 pages
10h 52m
English
You can use the keyword const for pointers before the type, after the type, or in both places. For example, all the following are legal declarations:
const int * pOne; int * const pTwo; const int * const pThree;
pOne is a pointer to a constant integer. The value that is pointed to can't be changed using this pointer. That means you can't write
*pOne = 5
If you try to do so, the compiler will object with an error.
pTwo is a constant pointer to an integer. The integer can be changed, but pTwo can't point to anything else. A constant pointer can't be reassigned. That means you can't write
pTwo = &x
pThree is a constant pointer to a constant integer. The value that is pointed to can't be changed, and pThree can't be changed to ...
Read now
Unlock full access