C++ › Const Correctness
What is the difference between const pointer and pointer to const?
IntermediateAnswer
'Pointer to const' (const int* p) means the pointed-to value can't be changed through p, but p can point elsewhere. 'Const pointer' (int* const p) means p can't be repointed, but the value can change. 'Const pointer to const' (const int* const p) fixes both. Reading right-to-left clarifies which part is const.
const int* a; // value const, pointer mutable
int* const b = &x; // pointer const, value mutable
const int* const c = &x; // both constReal-world example An API returns a const int* so callers can read but not modify the internal buffer, while reusing the pointer.