5.Reference_pointers
5.Reference_pointers
4. int a;
5. int *p=&a;
6. int &x=*p;//x indirectly refer to a through pointer variable p.
7. int &n =50;//creates an int object with value 50 and name n. but
gives error.
Pitfalls in Reference
Pitfalls in reference
Wrong Reason Correct
declaration declaration
int &i; No variable refer to-- must be initialized int &i =j;
int &j = 6; No address to refer as 6 is constant const int &j = 6;
int &i = j+k; Only temporary address (j+k) to refer to const int &i = j+k;
The return type of function min() is int '&' (reference), it indicates that the
call to function min() can be written on the left side of assignment operator.