Interview Question
Software Engineer / Developersreference is like a const pointer and it cannot be re-assigned.
syntactical advantage, as reference just appear as variable names instead of &(variable_name) /* example: incrementing operator for an enum type */
Reference is not const pointer. There is difference between Reference and const pointer. Const pointer will still create another memory to store address while reference doesn't allocate any new memory for storing address. They are like alias. They are still pointing to same original address.
References are safer than pointer.
- Random Guy June 18, 2011The compiler will make sure that they will point to some valid data
but in case of pointer it can point to NULL also.
At some place ,you are bound to use references ,for example
in operator overloading you will have to use reference .You can't use pointers.
Pointers are used where you want to be able to change the location of reference.
For example, Linked list and Trees.