Thursday, April 18, 2024

Why reference is not same as pointer?


 Answer: D

Here are some other differences between references and pointers:

Reference cannot be declared as NULL, while a pointer can be declared as NULL.

A reference must be initialized when it is created, and once it is, it cannot be made to alias another object. A pointer can be reassigned to point to other objects.

A reference is dereferenced implicitly and does not need the dereferencing operator * to retrieve the value referenced. A pointer needs to be dereferenced with * to access the memory location it points to.

A reference has the same memory address as the item it references. A pointer can change the address value stored in it.

Use pass-by-pointer if NULL is a valid parameter value or if you want to reassign the pointer. Otherwise, use constant or non-constant references to pass arguments. 


0 comments:

Post a Comment

Data Structures with C++



NET/SET/CS PG



Operating Systems



Computer Networks



JAVA



Design and Analysis of Algorithms



Programming in C++

Top