What are the differences between Pointers & References? 1. Both can be used to refer to any object of its type. But there is a difference in systax. Eg: int *p=&a; int &r=a; 2. A pointer can be NULL, whereas a reference has to be always pointed to some object. Eg: For pointers: int *p; // This is valid. int *p=NULL; // This is valid. int *p=&a; // This is valid. For references: int &r; // This is In-valid. int &r=NULL; // This is In-valid. int &r=a; // This is valid. 3. A reference once it is binded to an object, it cannot b...
Comments