Pointer Cheat Sheet

This page is based on information that appeared on the tear-out Cheat Sheet from C For Dummies, Volume II.

Pointer Pointers

Typical Pointer Setup and Use

First, create a pointer of the proper type:

float *f;

Second assign it to a variable's memory location:

f = &boat;

Finally, use the pointer:

printf("%.0f",*f);

Pointers, Parenthesis and Math

Pointer Thing Memory Address Memory Contents
p Yep Nope
*p Nope Yep
*p++ Incremented after value is read Unchanged
*(p++) Incremented after value is read Unchanged
(*p)++ Unchanged Incremented after it's used
*++p Incremented before value is read Unchanged
*(++p) Incremented before value is read Unchanged
++*p Unchanged Incremented before it's used
++(*p) Unchanged Incremented before it's used
p*++ Not a pointer Not a pointer
p++* Not a pointer Not a pointer

The ++ operator is used above, though any math operation can be substituted.

A tip: Use parenthesis to isolate part of the pointer problem and the answer will always work out the way you intended.

Pointers and array brackets

Array Notation Pointer Equivalent
array[0] *a
array[1] *(a+1)
array[2] *(a+2)
array[3] *(a+3)
array[x] *(a+x)

Ugly ** notation

Doodad What It Is Seen by The Compiler
array+1 An address A pointer
*(array+1) Contents of address, what lives there A string
*(*(array+1)) Contents of a character array A character
**(array+1) Same as above Same as above