I have difficulties in determining the types and usage of variables in terms of reference and pointers:
1. | int a = 10;
2. | int& b = a; // b is a "alias" of a or say, b is a reference of a
3. | int* c = &a; // c is a pointer to the mem location where it stores a
pointer and reference are different, so I read here;
why line 3 a pointer can be assigned with a reference?
2.1. or
&ais not a reference at all?if
&ais not a reference, what makes&ba reference?3.1. And why
&b == &aistrue?3.2. And why do we need
*to dereference (since pointer is not reference) in order to use it's value?if
&ais a reference, who do it refer to?a?4.1. if
&ais a reference, does it mean a reference is essentially a pointer (or vise versa)?4.2. if not, why a pointer can be assigned with a reference since they are different types?
4.3. if 4.1 is true, what are the particular situations that we do need both reference and pointer? Isn't a dereferenced pointer a reference to the variable it points to, that is:
*c == b; //true, the value of the vaiable
c == &b; //true, the address that stores the variable
*&b == a; //true, dereference a pointer gives the value
and
*c == &a; //illegal, why? Since at line 3 *c just be assigned with &a
I can keep going but I think the reset of my questions will be answered if I can get my head around the above questions.