Datasheet

Appendix C. The C Language
58
A pointer is specified by prefixing the name with an * in the declaration. Thus, int *n; specifies a
pointer, n, which points to an integer.
A pointer declaration does not allocate memory
The declaration of a pointer only allocates the pointer. It does not allocate any space for the thing that
might be pointed to.
An array is declared by suffixing the name with the ordinality surrounded by square brackets ([]).
Thus, unsigned long g[10]; would declare an array of 10 elements of unsigned long named g
and allocate the necessary memory. Array elements are numbered starting at zero, thus, in the above
example, valid elements are numbered zero through nine.
Since a pointer and an array name are the same, and may be used interchangably, incrementing a pointer
or an array name increments it by the size of the thing pointed to. The same holds for any arithmetic.
Thus, in the code below:
int array[10];
int *pointer;
int a;
pointer = array;
a = array[5];
pointer = pointer + 5;
a = *pointer;
a = array[5]; and a = *pointer; have the same effect.
Similarly, an "element" of a pointer may be specified. For example:
int array[10];
int *pointer;
int a;
pointer = array;
a = array[5];
a = pointer[5];
Character strings in C are simply arrays of char. The compiler treats these arrays no differently than other
arrays, except that there is a convenient way of expressing a string literal; it is simply a string of characters
surrounded by double quotes.
By convention, a character string is terminated by a NULL character. The compiler does not enforce
this, except that the compiler does provide the terminating NULL for a literal string. Most library routines,
however, count on this, so it is generally important to be sure the terminating null is preserved when
strings are manipulated.
When a character string is declared, it is important to include space to allow for the terminating NULL.
Thus char myString[10]; provides space for a nine character string plus the terminating NULL.