Apr 9, 2011

Reference vs. Pointer

In Software Engineering Project course we need to learn some C++ to develop the project. A question that some programmers have when passing from Java to C++ (like me) is “Which are the differences between pointers and references?“. You can find a lot of answers around developers forum, but I summarized them in the following table. Glad if you found it useful!

Reference Pointer
is an object which IS AN ALIAS for another object is an object that CONTAINS THE ADRRESS IN MEMORYof another object
the preferred way of undirectly access objects you should use it just if you really need it, as it lets you to work in a lower level than a reference does
keeps your code clear the code is less clear but still understandable
it must be initialized when created you don’t have to initialize it when declared
it references to the one object and only that one, therefore you can not modify the address referenced because it contains an address, it can point to many different objects during lifetime. The address can be manipulated
when used, the address is dereferencedwithout using any particular operator the address must be dereferenced using the * operator


written by dgraziotin

Dr. Daniel Graziotin received his PhD in computer science, software engineering at the Free University of Bozen-Bolzano, Italy. His research interests include human aspects in empirical software engineering with psychological measurements, Web engineering, and open science. He researches, publishes, and reviews for venues in software engineering, human-computer interaction, and psychology. Daniel is the founder of the psychoempirical software engineering discipline and guidelines. He is associate editor at the Journal of Open Research Software, academic editor at the Research Ideas and Outcomes (RIO) journal, and academic editor at the Open Communications in Computer Science journal. He is the local coordinator of the Italian Open science local group for the Open Knowledge Foundation. He is a member of ACM, SIGSOFT, and IEEE.

Leave a comment