I've studied Computer Sciences in high school (didn't go to college yet) and I've yet to understand: what exactly are pointers, and why the heck do we need them?
I'm probably really bad at explaining this and you should just listen to jota, but I like talking about this stuff so here we go.
An unhelpful answer as to why we need them: most problems in computer science can be solved by just an additional layer of indirection. (I think the actual quote may say "all problems" but whatever). Pointers are a layer of indirection (you see things like that a lot in pretty much all levels of software and even hardware).
As to what they are... everything in memory is, at some level, a number. Assuming C is the language you're dealing with... you say 'int x = 5;', there's a spot in memory with some bits representing "5" in it. "x" just represents an integer, whose value is that spot in memory. When you say "x+2", the number in that spot of memory is retrieved (5), and 2 is added to it, and you get back the result.
Pointers are also just numbers; they happen to represent a location in memory instead of representing an integer. You say "int * ptr = &i;" and there's a spot in memory with some bits representing the spot in memory for "i". But the value of 'ptr' is just a number, probably something like 0xbfd3a288 (in hexadecimal). All pointers are just simple numbers: char**'s, int*'s, void*'s, all of them.
The only thing that is different between them is what datatype you get when you dereference them. A location in memory is not very useful unless you know how to interpret what's there. So, if you dereference a char* to read from it, the compiler knows to look at the first byte, and that it represents a value between -128 and 127. If you dereference an int*, the compiler knows to look at the first four bytes (depending on the architecture), and that they represent a value between -2^16 and 2^16-1. If you dereference a 'struct whatever *' it knows to look at specific locations in memory and what they mean.
A real answer as to why we need them... well, there's many reasons. The answer that deals with how they are used with arrays isn't wrong, but to give a real "correct" explanation for that takes too much detail, in my opinion (memory allocation and such). The simplest way I could say is that it just lets you point to other objects, variables, etc, in a program. A simple example would be how you return more than one value from a C function. If you want to return two integers, you do something like "foo(&var1, &var2)" and somewhere "foo" does "*var1 = somevalue;" etc. Passing in a pointer lets the function set the value of some integers. What integers? The caller of the function decides, based on what pointers it gives "foo".
That may be more confusing than helpful, but I'm trying to prevent bringing out fuller code examples. Oh well, I enjoyed it.
Proud member of the Canadian Alliance.
dgf hhw