Hi All, can any one explain what is the exact difference between reference and pointer. what is advavantage of using reference over pointer. I have gone through some articles and books. But I am not much clear about this concept. What i feel is we can do everything with a pointer what ever can be done by a reference. so why there is a reference conecept . If possible suggest me some good articles only on these topics. Thanks
Pointers (address) can be NULL. Client can calls your API with NULL as argument. So if you do not check NULL every time before using a pointer GPF(crash) may occur. But such problem doesn’t occur with reference.
Pointers are pointing to some object but reference is nothing but the same object for which you have created that. In memory, you have different memory allocation for the object and pointer. But for reference, there is no seperate memory allocation. You can use arithmatic operations on pointer but not on reference (like you increment a pointer by one, it will point to next object).