What is a pointer exactly?

Throughout an introduction to computer science class, you may hear references made to wonderful things called pointers, but until you experience them for yourself, you're missing out on a wonderful world of possibilities. Pointers are a necessary facet of almost every computer program written, whether for personal, academic, or commercial use. This tutorial will explain when and how to use them.

What exactly is a pointer? Stated simply, a pointer is nothing more than a variable that holds an address in the computer's memory. This is where a pointer gets its name. A pointer variable holds the address of a certain piece of memory in the computer; in other words, a pointer points at a specific location in memory. In essence a pointer is nothing more than a variable that holds a number that is the address of a specific memory location.

Pointers and Memory

For now, let's think of memory as a big blob of storage space where we can put information that we later want to retrieve (this isn't far from the truth).

Figure %: The memory in our computer

Let's say we have a simple program as follows:

void main() { int steve; steve = 220; }

What happens when we run this program? First, the computer sets aside a little bit of memory to hold the integer steve.

Figure %: Memory set aside for steve

It then stores the value 220 into that variable.