Home Page

Learning C++ Pointers for REAL Dummies


You guys are brothers?

Well, if you noticed with the lesson How do I point to the neighbor?, arrays and pointers are very closely linked. In fact, they are kind of like brothers.

Let's say we have two brothers. One brother finds a girl, settles down with her, and stays with that woman for the rest of his natural life. He is very constant. The other brother is the complete opposite. He might stay with a woman for a day, a week, a month, or maybe a couple of years. He might somewhere in his life settle down, but he doesn't stick with only one girl. Well this is the same with pointers and arrays.

An array is really just a constant pointer. When you declare an array like:

int ramon[5];

ramon is actually a pointer that constantly points at the beginning of the array. We cannot point ramon somewhere else. To make a const pointer we would type:

const int *tony;

This will create a const pointer called tony. Once we initialize where tony will point, we cannot point him somewhere else or his wife will be mad... I mean the compiler will give you an error.

But, remember the wild brother can always point to the constant pointer...

int ramon[5];
int *paul;
paul = ramon;

Now, paul and ramon are pointing to the same thing; the first element of the array.

Where do you live? (&)
What you got in your house? (*)
Don't point, it's rude!
I am pointing here!
Where are you pointing?
How do I point to the neighbor?
You guys are brothers?
Beam me up Scotty, multiple times!!!
Quiz for REAL Dummies