Okay, here's the explanation I was given.
To understand variables and pointers in C, you really have to understand that variables in C aren't quite like variables in other languages.
Basically, most languages treat a variable as a box you put things in. You declare the variable, then you can store things in or retrieve things from it.
C treats variables a tiny bit differently. In reality, ALL variables are pointers, but "normal" variables are treated like permanently dereferenced pointers; that is, when you say somevar = 5; you're saying "the block of memory at the address pointed to by somevar is equal to 5."
When you declare a pointer, you're basically making a pointer that doesn't lie about being a pointer, so it 'naturally' acts like a pointer, so saying ptr = &somevar; is basically saying 'the address ptr points to is now the same as the address pointed to by somevar.' Now, if you dereference ptr, you are accessing the section of memory allocated to somevar. In other words, if you do *ptr += 2; you're setting whatever section of memory ptr points to, in this case the memory allocated to somevar, to itself plus 2, in this case setting itself to 7.
When you print out the value of somevar, after doing this, the output will be 7, even though you modified the value of somevar through ptr.
Code:
#include <stdio.h>
int main(void)
{
int *ptr; /*Declaring a pointer*/
int notaptr; /*Declaring a normal variable*/
notaptr = 5;
ptr = ¬aptr; /*Assigns the address of notaptr, instead of its value, because notaptr*/
/*is being made to act like a pointer because of the & in front of it.*/
*ptr += 3; /*The * in front of ptr makes it act like a variable, in this case*/
/*ptr is 'being' notavar, since that's the address it was assigned to.*/
printf("%d", notaptr); /*Prints 8, since the value of notaptr was modified using ptr*/
return 0;
}
Pointers can be used in a lot of ways, especially to allocate memory(often using arrays), or to allow a function to modify a variable local to another function(remember local variables which aren't static go away after their host function terminates!).
I may be wrong on some of these details, so if I am, someone please correct me.
Edited to complete the post, hit the save button instead of preview.
Edit: One notable use of pointers is with arrays. What an array is is basically a pointer that points to a number of variables of the array's type which reside in a contiguous section of memory.
In other words, you declare an array int somearray[10]; and you've basically got 10 int-sized sections of memory all in a row. When you assign a pointer to somearray's address, it's assigned to somearray[0]. When you assign a value to somearray[4], you can later access it by assigning the pointer to somearray, then incrimenting that pointer 4 times, which makes it move 'up' 4 times from somearray[0] to somearray[4]. If you were, after this, dereference that pointer, it would contain the value of somearray[4]. You could then incriment or decriment the pointer to point to other elements of the array as needed.
Again, I may be wrong in some(or all) of the details here, but I think that's basically how it works. I'm hoping as a fellow C-programmer-in-the-making, I can give you a lateral perspective on the subject, which might be lost to those who've come to accept this stuff as second nature.