Simple Pointer Examples in C Thanks to feedback in this thread, I'm beginning to plan how to integrate a basic introduction to pointers into my unit on arrays. Here's a sample program I just wrote up:

#include &lt;stdio.h&gt;

int main(void)
{
    int number = 42;
    printf("Value of number: %d\n", number);
    printf("Address of number: %p\n", &amp;number);

    int *pNumber = &amp;number;
    printf("Value of number pointer: %p\n", pNumber); 
    printf("Value at address of number pointer: %d\n", *pNumber);    
}


I will probably add comments before actually presenting it and making it available to students. Seeing how the address of number and the value of pNumber always correspond will hopefully reinforce how pointers work. The first and last line will match as well. The idea is to show as clear and simple an example as possible. 

My question comes in two parts:


Is this an appropriate example for introducing pointers?
Do you have suggestions for similar simple examples of basic pointer
usage?
I would teach the use of arrays and array indices first (with pictures of a long row of physical mailboxes, or school lockers, etc.)  Then later explain that all of a computer's and/or C program's (process) memory can be thought of as one big array with a pointer being a form of index (locker number) into that (virtual) memory array.

You can then draw a picture of how arrays of char (bytes) might be allocated in memory.  And then show why pointers might be necessary in order to tell a standard string function how to find (or modify) a substring in an arbitrary C string array.