It is the programmer's responsibility to stay within the proper bounds.
In particular, you must not let the subscript become negative for above N-1, where N is the size of the array.
Another situation in which an array's size need not be specified is when the array elements are given initial values.
As we will see in Chapter 9, the compiler will determine the size of such an array from the number of initial values. Most obviously, we can write subscripted references to array elements, as we have already seen.
Multi-dimensional arrays require multiple sets of brackets.
The examples in Listing 8-1 are valid declarations.short data; /* define data, allocate space for 5 16-bit integers */ char string; /* define string, allocate space for 20 8-bit characters */ int time,width; /* define time, width, allocate space for 16-bit characters */ short xx; /* define xx, allocate space for 50 16-bit integers */ short pts; /* define pts, allocate space for 125 16-bit integers */ extern char buffer; /* declare buffer as an external character array */Notice in the third example that ordinary variables may be declared together with arrays in the same statement.
The statement If the array has two dimensions, then two subscripts are specified when referencing.
As programmers we may any assign logical meaning to the first and second subscripts.
Although arrays represent one of the simplest data structures, it has wide-spread usage in embedded systems.
Strings are similar to arrays with just a few differences.