pointers and references

I was reading Programming Interactivity and they started getting into pointers and references and how to use them. I am a complete beginner and this was pretty intense for me. Read it several times and still don’t understand their examples, but I can see it’s important because it might cause performance issues later, which is no good.

anyway, anyone have a good reference for learning more about these and their applications? need something very beginner-esk

Spend an afternoon going through this, excellent resource imo: http://www.learncpp.com/
Pointers start here: http://www.learncpp.com/cpp-tutorial/67-introduction-to-pointers/

As a beginner, the biggest, most useful difference is that pointers can be NULL

I have most often needed them when dynamically allocating objects (particle systems come to mind)

awesome, thanks a ton!

Just for the record: I rewrote that whole section in the new edition of Programming Interactivity :slight_smile: New examples and much more explanation.

One of the things I found useful when I first started working with pointers is to make sure that you know where they are all the time, i.e. that a classs contains them, so you know where to go when you need to delete them.

Another really important thing is the difference between delete[] and delete.

foo *p = new foo();  
delete p;  

foo *p = new foo[3];  
delete[] p;  

My rule of thumb is: use references when you just want to modify something somewhere else, use pointers when you want to dynamically create something and not have it be confined to one place (which is less often that you think tbh).

I think the part that really confuses me is that does one actually just store the location and the other stores the object or value? this is where I got confused.

yeah, confusing, that’s pointers. :slight_smile:
Have you read what I linked to above? It doesn’t get much simpler/clearer than that…

I just did, makes a LOT more sense. Thanks for the links, this is good stuff.