[previous_group] * [up] [next] [next_group]


An array is a compound data structure that lets us group together many variable cells, all of the same type, into one unit, giving it one name.

Declaring an Array

We delcare an array by giving its type, name and size:
        int data[100];
        char str[81];

Such declaration statements declare(tell the compiler), and define(allocate the memory cells) for these arrays. The memory cells are allocated in one block in adjacent locations in memory:

Each cell has an index - an integer label which can be used to identify and access individual data items in the array (remember, the name refers to the ENTIRE array. We access (read or write) an individual element of an array with a subscripting expression of the form:


where <identifier> is the name of the array, and <expression> is an integer valued expression which evaluates to the index of the element being accessed. For example:
     data[35] = 30;


the indexes for the elements of the array range from 0 to size-1.

But what is really going on when we declare an array?

[up] to Overview.