Could someone please explain to me exactly how pointers work? For some reason I'm not getting it. I read the tutorial here all thoroughly but I'm still left in the dust.
Could someone please explain to me exactly how pointers work? For some reason I'm not getting it. I read the tutorial here all thoroughly but I'm still left in the dust.
My best code is written with the delete key.
My standard "homework" analogy...
Sally doesn't know the answer to the homework, but she knows who does... Sally is a pointer. Bob has the answers, but you don't know that... maybe you don't know where Bob lives. (In a program, Bob doesn't have a name, only an address).
If you ask Sally what she knows, she will give you Bob's address:
Answer = Sally; // Answer now equals Bob's address... not what you want
You can tell Sally to go get the answer.
Answer = *Sally // Answer now equals the real answer.
The most common use for pointers is when a function needs to modify or return more than one value. For example, when you need to modify a string.
Last edited by DougDbug; 11-21-2003 at 03:02 PM.
Sparknotes has some good pointer tutorials, with nice visuals:
http://www.sparknotes.com/cs/
----[Red Haze]----