Your stack/heap understanding seems good; but to explain pointers I'll have to start with a fairy tale about ***A NIGHTMARE WORLD WITH NO POINTERS***.
If pointers did not exist then you would be forced to make copies of objects every time you added them to arrays or passed them into methods. For example, suppose you had an array of "Person" objects and you wanted to change all of their middle names to "Bubba." You would have to do something like this:
Code:
for(int i=0; i<[peopleArray count]; i++){
Person person = [peopleArray objectAtIndex:i]; //copy the person
person.middleName = @"Bubba"; //copy the Bubba string into each object!
[peopleArray replaceObjectAtIndex:i withObject:person]; //copy him back
}
All that copying would be terribly slow! What if we lived in a better world, where you didn't have to copy an object to add it to an array? Suppose the array could just get the address of the original object and keep track of the object that way? That's what a pointer is, the address of an object*. I could also access the array by getting a pointer to the object inside the array.
Luckily this is the world we live it; Objective-C uses pointer all over the place, and our code can get much simpler:
Code:
for(int i=0; i<[peopleArray count]; i++){
Person *person = [peopleArray objectAtIndex:i]; //get a pointer, not a copy
person.middleName = @"Bubba"; //point the middleName pointers at the same Bubba string
//no need to copy back; I modified the original object right inside the array.
In our world of pointers programs can be shorter and use less memory and run much faster because there is less copying going on.
*Pointers are not just used with objects -- you can have pointers to integers and other primatives -- but it's not as common in Objective-C.