Cosntant pointer

I am reading c++ primer 6th edition. here i encountered a example
int * const pr = &rats;
As far i understand it should be like
int const *pr = &rats;
Even if i try to compile it in devc++ it does not compile. Is that example correct or i am missing something?

Thanks.
i think its correct. im not on my mint machine right now so i cant test it out, but i think the top one is a constant pointer to an int (ie you cant point it to something else) and the bottom one is a pointer to a constant int (ie it can point to any const int)
const is attached to the left. Unless it is first then to the right. So
1
2
const int *pr = &rats;
int const *pr = &rats;
are different then int * const pr = &rats; The first example I showed is a pointer to a constant integer and the latter is a constant pointer to a mutable integer.
"You have to read pointer declarations right-to-left. "
http://www.parashift.com/c++-faq/const-ptr-vs-ptr-const.html
Topic archived. No new replies allowed.