Possible Duplicate:
what is the difference between const int*, const int * const, int const *
i have a cpp code wich i’m having trouble reading. a class B is defined
now, i understand the first two lines, but the rest isn’t clear enough.
is the line “B const * pa2 = pa1” defines a const variable of type class B?
if so, what does the next line do?
B a2(2);
B *pa1 = new B(a2);
B const * pa2 = pa1;
B const * const pa3 = pa2;
also, i’m having trouble figuring out the difference between these two:
char const *cst = “abc”;
const int ci = 15;
thank you
This code declares a pointer to a constant
B– in other words, it cannot be used to change the value of what it is pointing to:Alternatively, the following code declares a constant pointer to a constant
B– so,pa3cannot be used to change the value of what it is pointing to, and it cannot be modified to point to something else:This page contains an explanation of
constpointers.To address your second question,
char const *cst = “abc”;– Declares a pointer to a constant char – in this case it is the string “abc”.const int ci = 15;– Declares a constant integer15, which cannot be changed.