Advertisement

Analogies for pointers?

Started by April 18, 2002 12:35 AM
2 comments, last by Gamersez 22 years, 6 months ago
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"
A shortcut is the longest distance between two points.
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]
[email=ubc_wiskatos@hotmail.com" target="_blank" style="width: 10px; height: 10px; background: #fe7a21; overflow: hidden; display: block; margin-bottom: 2px;][/email]Wiskatosxp
Advertisement
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
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.

This topic is closed to new replies.

Advertisement