• Advertisement

Archived

This topic is now archived and is closed to further replies.

Analogies for pointers?

This topic is 5754 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Greetings all, I am taking a game design course and am struggling to get a grasp on *pointers, along with using the & (ampersand) sign. Question- How do you relate pointers and & in an analogy to best communicate how they are used, and where they are used in C++. Feel free to post your analogies. Hopefully this will help many, not just myself. "I Vanna Fryyyy Skyyyy Hiiiiiiigh! Vroooll to get Vyyy!" -Sega''''s "Daytona USA"

Share this post


Link to post
Share on other sites
Advertisement
Let's say you have a piece of paper. You place the piece of paper in your room. The piece of paper can't leave your room.

Let's say you can do only one thing in each room of your house. In the next room, you can rip pieces of paper up into little bits. What if you want to rip the original piece of paper?

You can make a copy of it, and rip it in the ripping room, but the paper in your room will still be intact.

The answer? Pointers. A pointer is like a portal to the piece of paper in your room. With the pointer, you can now directly edit the piece of paper and rip it up, without exiting the room where you can rip up paper. :-)

[edited by - UBC_Wiskatos on April 18, 2002 10:32:36 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
When I was taking my intro CS courses in University I thought that analogies made things more complicated then they had to be. An int is a variable type right? Well if you say "int x" then the variable has to be stored somewhere in memory, at some particular address. You computer knows that when it looks at the 1''s and 0''s at that memory address that it should interpret them as a number. Well all a pointer is is a variable whose 1''s and 0''s should be interpreted by your computer as an address somewhere in memory. So if you have "int *p" then the 1''s and 0''s where p is stored tell you where some integer is stored in memory. Thats all a pointer is, there is nothing more complicated to them then that. It is a little more complicated to learn when/why/how to use them properly though.

Good Luck

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Lets say we are in the same room. We are separate entities taking up separate space. I am pointing at you (literally). If someone whats to find you they can follow where I am pointing and they will find you. Thats what pointers do except they do it for memory locations.

Share this post


Link to post
Share on other sites

  • Advertisement