ravindra mudumby
New User
Joined: 16 Jun 2005 Posts: 6 Location: blore
|
|
|
|
An array is a collection of data items, called array elements, of the same type, and stored in adjacent memory cells. All data in an array is associated with a symbolic name.
As other data types, an array needs to be declared before it can be used.
The declaration "double x[8];" instructs the compiler to associate eight memory cells, each can hold a double value, with the name x.
Variables in an array are not named individually, but though the array name and an index, or subscript, value, which is a serial number starting at 0. For example, the subscripted variable x[0] (read as x sub zero) may be used to refer to the first element in the array x, x[1] the next one, and so on. In C, if an array is declared to contain n elements, the range of valid index values is from 0 to n-1. For example, FIGURE 8.1:
After declaration, each element in the above array can be used as a normal double value.
An array can be initialized in the same statement as it is declared, such as
int squares[] = {0, 1, 4, 9};
Please note that in this kind of declaration the size of the array is implied by the number of the initial values. Also, this format can only be used in initialization, but not in any assignment after it.
2. Array subscripts
It is important to understand the relation and difference between a subscript of an array and the associated value stored in the corresponding memory cell.
A subscript can either be a constant integer, or a variable or expression that has an integer value. |
|