Pointer Basics

What is a Pointer?

A pointer is a variable that stores a memory address.  Pointers are used to store the addresses of other variables or memory items.  Pointers are very useful for another type of parameter passing, usually referred to as Pass By Address.  Pointers are essential for dynamic memory allocation.

Declaring pointers:


Notation: Pointer dereferencing

pdeclare.cpp -- an example illustrating the declaration and dereferencing of pointers
 

Initializing Pointers

So, how do we initialize a pointer? i.e. what can we assign into it?
  int * ptr;
  ptr = ______;		// with what can we fill this blank?
Three ways are demonstrated here. (There is a 4th way, which is the most important one. This will be saved for later).

The null pointer

Pointers of the same type

The "address of" operator