I really do not see the difference between these two declarations:
int myvariable;
int * mypointer;
It is said that when you define a pointer, instead of containing actual data, it contains a pointer to the memory location where information can be found.
But doesn't the other variable declaration do the same? It obviously doesn't have data either. And it must be stored in a memory location as well. So I do not see the difference.
int myvariable; creates an object of type "int", name "myvariable", and indeterminate value
int* mypointer; creates an object of type "int*", name "mypointer", and indeterminate value.
they are simply two different objects of different types. If you need to store a number, it can be stored in myvariable (myvariable = 7;) and not in mypointer. You can write std::cout << myvariable*10; to multiply and print it out as a decimal number.
If you need to store the address of some object of type int, it can be stored in mypointer, and not in myvariable. You can't multiply it, and if you print it, you will see a hexadecimal number. There really is almost nothing in common.
You'll know when you need them.
For example, operator new can only return a pointer. Or, for another example, an object may need to keep track of another object that exists elsewhere or can be replaced at any time.
In general, do not use a pointer unless you know that you can't do without one. And as Cubbi points out, you'll know when you need one.
A pointer is one way of indirectly referring to an object, and the idea of referring to another object is immensely useful in practice. For instance, I share my mother with my siblings, we all refer to the same mother; in programming terms, each of us can't define a separate mother - all of us refer to or 'point' to the same mother. For a person whose mother is no more, the pointer would be a null pointer; a pointer that does not point to an object.
The most common use of a pointer (or something that has pointer semantics) is when we want to iterate through a sequence. For example, if we have a list of books (we do not know how many books there are at the time we write the code), and we want to print out the title and author of each of these books, our code would look something like:
1 2 3 4 5 6
initialize a pointer to point to the first book.
repeat:
print out the title and author of the book pointed to
make the pointer point to the next book
if the pointer is not null (there is a next book), go to repeat
else we are done.