Since these differences are a matter of semantics rather than specific limitations imposed by the syntax of the C programming language, the descriptions in this chapter apply equally to data arrays and character strings.
String literals were discussed earlier in Chapter 3; in this chapter we will define data structures to hold our strings.
For example we could consider the first subscript as the row and the second as the column.
Then, the statementcopies the information from the 4th row 6th column into the variable The Position.
The subscript itself can be any legitimate C expression that yields an integer value, even a general expression.
Therefore, arrays in C may be regarded as collections of like variables.
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 first element occupies position zero, the second position one, and so on.
It follows that the last element is subscripted by [N-1] where N is the number of elements in the array.