What's the point? A lecture on pointers. Pointers are exactly what they say they are. They point. They point to the location of another variable in memmory. Why use them then? They server no real purpose in life right? Well, actually they do. You've probably already used them without even knowing it. Defining pointers: char variable = 'G'; //a variable char * pvariable; //a pointer (note: the p is not necessary, it just help //s us to remember that it's a pointer. pvariable = &variable; //links the pointer to the variable. cout << *pvariable; //prints "G" Ok. You're probably wondering what all those *s were for. Well let's go through this line by line. char variable = 'G'; Standard definition and initialization of a character variable. char * pvariable; Definiton of a character pointer. The * is what tells the compiler that this is actually a pointer. Now why wouldn't you just have a pointer variable type? Well here's why: different variables are different lengths. For example: a long takes up 8 bytes, while an int takes up only 4. The pointer must be defined as the same type as the target so that the program knows how big the variable is. pvariable = &variable; This puts the address of variable in pvariable. (more on this later) cout << *pvariable; This ouputs G as opposed to the addr. of variable. (more on this later). Hey? What do those *s and &s do? Well the & can be read as "the address of". So read pvariable = &variable; as "place the address of variable in pvariable". Got it? The * is called the dereferencing operator. It goes to the pointer, then goes to the address that the pointer points to, before fetching the data. This causes cout << *pvariable; to output G as opposed to a lenghy addr. The * went to the addr contained in pvariable and fetched the G. Note: DO NOT CONFUSE the deref. operator with the * at the definition of pvariable. They are two DIFFERENT things!!! Ok, now that you know what pointers are, why are they there? Look at this example (note... this covers passing arguments to functions... you should already know this): #include void doubleit( int myNum ); void main(void) { int myNum; myNum = 5; doubleit( myNum ); cout << "In main() mynum is " << myNum; return(0); } void doubleit( int myNum ) { myNum *= 2; cout << "The value of myNum is " << myNum; return; } If you were to run this code it would produce the following output: The value of myNum is 10 In main() mynum is 5 !?! Why wasn't mynum changed? Because it was passed by value. In order to change mynum in main you must pass it by address. Take a look at the same program, but changed slightly: #include void doubleit( int * myNum ); void main(void) { int myNum; myNum = 5; doubleit( &myNum ); cout << "In main() mynum is " << myNum; return(0); } void doubleit( int *myNum ) { *myNum *= 2; cout << "The value of myNum is " << *myNum; return; } This program produces the following output: The value of myNum is 10 In main() mynum is 10 And as you can see, since we pass it by address it changes the value. Now: what does this have to do with pointers? Well when you pass something by address you actually pass a pointer to it. That's why you use the deref *. This is the main use for pointers. Now we go to dynamic memmory allocation and linked lists.