Declaring and initializing arrays
An array is a collection of two or more values, all of which have the same type and share a single common base name. It makes no sense to have an array of just one value; that would simply be a variable. An array definition has the following syntax: dataType arrayIdentifier[ numberOfElements ];
Here, dataType
is any intrinsic or custom type, arrayIdentifier
is the base name of the array, and numberOfElements
specifies how many values of dataType
are in the array. numberOfElements
, for whatever type and values are given, is a literal constant or expression that will be converted to an integer. Most commonly, numberOfElements
is an integer constant expression. An array whose size is defined by a constant expression we call a constant-length array. All the elements of the array are contiguous (or side by side) so that the size of the array is the size of each element multiplied by the number of elements in the array. Once an array is declared, its size...