As we know in reference, a const can have a reference to either a const or non-const. However I have a question for the following pointer:
#include<iostream> using namespace std; int main() { const double pi = 3.14; const double *cptr = π //we point to a const double (above) double dval = 3.14; cptr = &dval; cout<<*cptr<<endl; } What I am not understanding is "const double *cptr" if we read it from right to left we have cptr is a pointer that points to a const double.
However, below we have double dval = 3.14; with cptr = &dval; double dval is not a constant, from what I am understanding we can still point to a non constant correct?
constinconst double *cptrsimply means "cptr can not change the double it points to".constdoesn't really mean "constant" nearly as much as it means "read only". Having a read-only pointer to a writable item just means you can't write to the item via that pointer.constvariable