Previous: Chapter 9
Up: Table of Contents
Previous Page: Chapter 9
Next Page: 9.1 Two Dimensional Arrays
In Chapter we have seen that C provides a compound data
structure for storing a list of related data.
For some applications, however, such a structure may not
be sufficient to capture the organization of the data.
For example, in our payroll task, we have several pieces of
information (hours worked, rate of pay, and regular and over time pay)
for a list of employees.
We have organized such data as individual arrays, one for each ``column'',
to form the payroll data base; but conceptually, this information
is all related.
In this chapter we will introduce a data structure which allows us to
group together all such information into a single structure - a two
dimensional array.
For a data base application, we can think of this 2D organization
as an array of arrays.
As another example of where such a structure is convenient, consider
an array of names.
We have seen that we can store a name in a string, which is
an array of characters.
Then an array of strings is also an array of arrays, or a two dimensional
array.
In this chapter we will discuss how we can declare two dimensional arrays, and use them in applications. We will see how we can access the data in such a structure using indices and pointers, and see how this concept can be extended to multi-dimensional arrays. We will present examples of 2 dimensional arrays for data base applications, string sorting and searching, and solutions to systems of simultaneous linear algebraic equations, useful in scientific, engineering, and other applications, e.g. electronic circuit analysis, economic analysis, structural analysis, etc. The one restriction in the use of this data type is that all of the data stored in the structure must be of the same type. (We will see how we can remove this restriction in the next chapter).