# Thread: I'm trying to visualize pointers.

1. ## I'm trying to visualize pointers.

I've been reading alot about pointers, and I'm only half understanding them. I understand what pointers do. I understand how they are useful. I understand that declaring them and pointees. What I really need is to be able to visualize them so I can remember them and then use them more effectively in practice.

So, if you will bare with me on my possibly odd analogy and let me know if I have this right or not...

We have a fictional city named "Memory City". In Memory City there are lots of houses, each with their own addresses. On resident of Memory city is "Sue". Sue lives at "123 Some Street".

So...

If I wanted to tell the mailman where sue lived I would use "&SuesHouse" correct???

If I wanted to get Sue out of her house I would use "*SuesHouse" (*SuesHouse == "Sue")???

Bah, and I don't even know a good analogy for "SueHouse" to be used.

------

Can anyone help me? Prefurably using a simular analogy?

Thanks!

2. Originally Posted by JesterJAG

If I wanted to tell the mailman where sue lived I would use "&SuesHouse" correct???

If I wanted to get Sue out of her house I would use "*SuesHouse" (*SuesHouse == "Sue")???

Bah, and I don't even know a good analogy for "SueHouse" to be used.
you're almost right. Assuming SuesHouse is the address of Sue, we have
Code:
```Person Sue;
Person *SuesHouse = &Sue;

cout << "Sue lives at " << SuesHouse; // outputs "Sue lives at 0x1230BDEE"

cout << "the person living at " << SuesHouse << " is " << *SuesHouse; // assuming Person object have a << operator```

The answer is at John's house. For some reason, you can't directly get the answer from John. (Maybe John doesn't even have a name.... but there's a house out there somewhere with the answer in it.)

Sue's house is a pointer. She doesn't have the answer, but she has John's address, and she can get the answer from John for you.

4. Originally Posted by JesterJAG
I've been reading alot about pointers, and I'm only half understanding them. I understand what pointers do. I understand how they are useful. I understand that declaring them and pointees. What I really need is to be able to visualize them so I can remember them and then use them more effectively in practice.

So, if you will bare with me on my possibly odd analogy and let me know if I have this right or not...

We have a fictional city named "Memory City". In Memory City there are lots of houses, each with their own addresses. On resident of Memory city is "Sue". Sue lives at "123 Some Street".

So...

If I wanted to tell the mailman where sue lived I would use "&SuesHouse" correct???
Close. You would tell them SuesHouse, or &Sue.
SuesHouse == &Sue ("The address of Sue") == "123 Some St."

If I wanted to get Sue out of her house I would use "*SuesHouse" (*SuesHouse == "Sue")???
Yes. Sue == *SuesHouse ("the thing at address SuesHouse")

Another analogy is to imagine you have a filing system where each piece of paper is put in a uniquely numbered file.

&Paper would give the number of the file that this paper is in.
*File would give the contents of the specified file.

A pointer then is just like writing down the number of one of the files on a post-it; a pointer is a variable that tells you where something else can be located. Rather than streets or files it's an address into the computer's memory.