I can't understand pointers and references. Please help.

Hi, I'm learning C++ using this website: http://xoax.net/cpp/crs/console/lessons/Lesson17/

and I can't understand the reason why pointers and references are used, other than giving the same exact memory address two names. I've tried googling it to find some kind of simplified or better explained explanation, but to no avail. Please explain it to my malfunctioning brain as I can't seem to grasp the concept.

Thanks!

P.S. if you have some spare time, please also bring some actual code examples. Like one using pointers and one without. Extra thanks!
A reference is an alias. Just like some refer to Bessie, while other call the person Elizabeth.

A function argument can be by reference. That allows the function to modify a variable of the caller. There are also other means to return data from function, but reference arguments are rather convenient.


Pointer is like an address-card. You can check from it, where Bessie lives. It is not Bessie. It can be updated to have address of John instead, or even wiped empty.

Pointer is a variable that stores a value that is interpreted to be an address. Run-time polymorphism depends on availability of pointers. What is polymorphism? Probably a later (much) chapter.
Topic archived. No new replies allowed.