References vs Pointers Both references and pointers can be used - TopicsExpress



          

References vs Pointers Both references and pointers can be used to change local variables of one function inside another function. Both of them can also be used to save copying of big objects when passed as arguments to functions or returned from functions, to get efficiency gain. Despite above similarities, there are following differences between references and pointers. References are less powerful than pointers 1) Once a reference is created, it cannot be later made to reference another object; it cannot be reseated. This is often done with pointers. 2) References cannot be NULL. Pointers are often made NULL to indicate that they are not pointing to any valid thing. 3) A reference must be initialized when declared. There is no such restriction with pointers Due to the above limitations, references in C++ cannot be used for implementing data structures like Linked List, Tree, etc. In Java, references don’t have above restrictions, and can be used to implement all data structures. References being more powerful in Java, is the main reason Java doesn’t need pointers
Posted on: Sun, 31 Aug 2014 15:14:55 +0000

Trending Topics



Recently Viewed Topics




© 2015