That mysterious independent variable of political calculations, Public Opinion.
In constructing our building, we have identified each brick (variable) by name. That process is fine for a small number of bricks, but what happens when we want to construct something larger? We would like to point to a stack of bricks and say, “That’s for the left wall. That’s brick 1, brick 2, brick 3...”
Arrays allow us to do something similar with variables. An array is a set of consecutive memory locations used to store data. Each item in the array is called an element. The number of elements in an array is called the dimension of the array. A typical array declaration is:
/* List of data to be sorted and averaged */ int data_list;
The above example declares
data_list to be an array of three elements.
data_list are separate variables. To
reference an element of an array, you use a number called the
index—the number inside the square brackets ([ ]). C is a funny
language that likes to start counting at 0. So, our three elements are
numbered to 2.
Common sense tells you that when you declare
data_list to be three elements long,
data_list would be valid.
Common sense is wrong and
data_list is illegal.
Example 5-1 computes the total and average of five numbers.
[File: array/array.c] #include <stdio.h> float data; /* data to average and total */ float total; ...