A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing


  • 4 years ago

What is the difference between a pointer and a reference in C++?

  • This Question is Closed
  1. asnaseer
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    There is a very good description of the differences here: http://www.dgp.toronto.edu/~patrick/csc418/wi2004/notes/PointersVsRef.pdf

  2. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    The link given in the previous answer is a pretty good answer. But, it is easy to miss the point that there is in C++ both pointers and reference are ways of storing and working with actual memory addresses. They are the same thing. So... why have two different names, and two different syntaxes, for THE SAME THING? Well, pointers can be cast to have not type. That is, they can be treated as pointing to raw bytes of memory, and then you can to all sorts of mischief. Pointers do have types, but it is easy to make horrible mistakes with pointers and very difficult to find them. References are just easier to keep straight in your head and therefore less error prone. C++ uses strong typing to find all sorts of errors at compile time. And, also to enable a vast number of optimizations, that are only possible because of strong typing. So, the designers of C++ decided to add references in the hopes of weaning C programmers away from using pointers. It is one thing to know that the difference between pointers and references is only syntactic, and not semantic. It is another thing to understand why someone would add a syntactic alternative to a semantic feature that is already in a language.

  3. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Also keep in mind that references can normally be assumed to not be invalid (whereas pointers should always be checked for 0). There's only one *easy* way to get a dangling reference (returning a reference to a temporary) - other than that, you'd actually have to build some pretty contrived code to construct a dangling reference. Pointers still have their place, but I agree with stonewolf in many respects - references should today mostly replace passing pointers to objects as arguments to functions, for example.

  4. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...


  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.