Warm tip: This article is reproduced from serverfault.com, please click

What is a Pointer?

发布于 2008-09-30 16:32:28

See: Understanding Pointers


In many C flavoured languages, and some older languages like Fortran, one can use Pointers.

As someone who has only really programmed in basic, javascript, and actionscript, can you explain to me what a Pointer is, and what it is most useful for?

Thanks!

Questioner
defmeta
Viewed
0
JosephStyons 2008-10-01 00:42:58

Pointers are not as hard as they sound. As others have said already, they are variables that hold the address of some other variable. Suppose I wanted to give you directions to my house. I wouldn't give you a picture of my house, or a scale model of my house; I'd just give you the address. You could infer whatever you needed from that.

In the same way, a lot of languages make the distinction between passing by value and passing by reference. Essentially it means will i pass an entire object around every time I need to refer to it? Or, will I just give out it's address so that others can infer what they need?

Most modern languages hide this complexity by figuring out when pointers are useful and optimizing that for you. However, if you know what you're doing, manual pointer management can still be useful in some situations.