I ll give you a description providing you know the basics of the memory. If you don't like my way of describing it just skip the post :P. There are better ways to describe it. Just google if you want.
Generally, a pointer is a variable that points to other variables. It does this by storing their memory address. So if you have variable A and you have pointer B then you can set B to point at A. Thus you will have
B --> A
You can now change the value of A through B. You can make B point to another variable as well. That is the usefulness of a pointer.
More detailed. First of all, all variables are places in the memory. Imagine the memory as a set of blocks. Each block has an address and a value. Lets say we have this two memory blocks which both have a value 0. Like:
Address Value
1234 [0]
1235 [0]
Now, when you declare a variable, lets say int myInt then you "allocate" one memory space. In other words you give a name to a memory space. So you would have:
1234 [0] myInt
1235 [0]
So, when you do myInt = 12 + 2, then the value 16 will be stored in the memory address 1234, which is the memory location that is named myInt. So you would have:
1234 [16] myInt
1235 [0]
No, what is a pointer. A point is again a variable. It has normally values. The difference is that this values refer to memory address. Like if you do this:
then you might have this:
1234 [16] myInt
...
1241 [...] myPtr
The memory address the variable is stored is something the system chooses for you. Just use random number for my example. So if you do this now myPtr = 12 again you will have:
1234 [16] myInt
...
1241 [12] myPtr
The point is NOT to do that though. The value has to be some address in the memory. Lets say you want myPtr to point to myInt. Then you would store the memory address of myInt to myPtr. You wouldn't do though myPtr = 1234 because you don't know the memory address, and you don't need to know! You do this:
The
& symbols takes the address of the variable. What is the address of myInt?? It is 1234. So now your memory will look like this:
1234 [16] myInt
...
1241 [1234] myPtr
You will want to think it like this though:
1234 [16] myInt
...
1241 [&myInt] myPtr
Because you don't care about the actual number. Why would you do all this, you ask? Because now you can use the value of myInt using myPtr. To do that you use the * symbol. Lets say you want to put in b the value of myInt. You know that myPtr "points" to myInt. So instead of doing this:
you can do this, with the same result:
How is this achieved? The program reads the value of myPtr. Which is &myInt, or in other words 1234. You tell it to get the value from that address (since you have the * symbol). So it will take the value from the memory address 1234. Thus, the value 16.
That is all. Don't know if it makes sense.