So far we have used only the fundamental data type, namely char, int, float, double and variations of int and double and variation s of int and double. although these types are very useful, they are constrained by the fact that a variable of these type can only store only one value at any given time. Therefore, they can be used to only handle limited amounts of data. In many applications, however, we need to handle to large volume only to handle this. To process such large amounts of data, we need a powerful data type that would facilitate efficient storing, accessing and manipulation of data, we need a powerful data types that would facilitate supports a derived data types known as array that can be used for such applications.
An array is fixed-size sequenced collection of elements of the some data type. It is simply a grouping of like-type data. In its simplest form, an array can be used to represent a list of numbers, or a list of names. Some examples where are concept of an array can be used:
1. List of temperatures recorded every hour in a day, or a month, or a year
2. List of employees in an organization.
3. List of products and their cost sold by a store.
4. Table of daily rainfall data.
and so on.
Since an array provides a convenient structure for representing data, it is classified as one of the data structure in C. Other data structure include structures, lists, queues an trees. We can use array to represent not only simple list of values but also tables of data in two or three or more dimensions. in this chapter, we introduce the concept of an array and discuss how to use its create and apply the following type of array.
1. One-dimensional arrays
2. two-dimensional arrays
3. Multidimensional arrays
a. Derived Types
b. Fundamental Types
1. Integral Types
2. Float Types
3. Character Types
c. User-defined Types
In addition to array an structures, C supports creation and manipulation of the following data structures:
1. Linked Lists
Like other languages, C uses arrays as a way of describing a collection of variables with identical properties. The group has a single name for all of the members, with the individual members being selected by an index. Here’s an array being declared:
The name of the array is
ar and its members are accessed as
ar through to
ar inclusive, as Figure 5.1 shows.
One important point about array declarations is that they don’t permit the use of varying subscripts. The numbers given must be constant expressions which can be evaluated at compile time, not run time. For example, this function incorrectly tries to use its argument in the size of an array declaration:
/* FORBIDDEN */ }
It’s forbidden because the value of x is unknown when the program is compiled; it’s a run-time, not a compile-time, value.To tell the truth, it would be easy to arrays whose first dimension is variable, but neither Old C nor the Standard permits it, although we do know of one Very Old C compiler that used to do it.That’s all very well, but does it really matter in practice? Not much it’s true; but it is interesting to note that in terms of actual machine storage layout the rightmost subscript ‘varies fastest’. This has an impact when arrays are accessed via pointers. Otherwise, they can be used just as would be expected.