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 declaration

  • Declared the same like other variables
  • Each variable being declared as a pointer must be preceded by an asterisk (*)
  • Could be any valid type (int, char, FILE, ADT)
  • Type indicates object that pointer refers to
  • Pointers and nonpointers can be declared in the same statement

 

Example:

char         y = 'A';      // variable declaration and initialization
int          x, *xPtr;     // pointer declaration in the same statement
int          *cursor;      // more pointer declarations
FILE         *outputFile;  
long         *sum;