Overview

Why use pointers?

What's a pointer?

Declaring pointers

Initializing/Setting pointers

Pointer operators

Pointer arithmetic

Pointers as parameters

Pointers vs. arrays

Array of pointers

Function pointers

 


Pointers initialization

  • Can be initialized when declared
  • Assign value with assignment statement
  • Value assigned to a pointer variable must be address of object of the proper type
  • Object must be previously defined
  • Can be initialized to a special value 'NULL', which points to nothing

 

Example:

char         x = 'A';      // variables declaration and initialization

char         z = 'C';
int          y = 32;        



int          *cursor;      // pointer declarations

int          *temp = NULL; // pointer declaration and initialization

char         *xPtr = &x;   // pointer declaration and initialization
                           // to a variable of the same type.




cursor = &y;               // set cursor pointer to variable y
xPtr = z;                  // redirect xPtr from variable x to z 
...