I'm currently reading c++ Primer and in one of the exercises, it shows 2 types of reference initializations, one const and and one not, and in the one const, the reference points to 0.. I thought references could only point to objects!!
int i = -1, &r = 0; // illegal, r must refer to an object.
const int i = -1, &r = 0; // legal.
So the first one, int variable i is -1. Then int reference r refers to 0 which is invalid,gotcha
Now in the second one, const int i = -1, then const reference r = 0.. How?
I know references can't be const, the const is what the reference is referring to, and the book said that const references can refer to both const and non const objects(of the same type). This still doesn't explain why it can point to 0, which is not an object at all..
I'm not sure how the second statement is valid, someone please explain!