array
s occupy space in memory. To specify the type of the elements and the number of elements required by an array
use a declaration of the form:
array< type, arraySize > arrayName;
The notation <
type,
arraySize>
indicates that array
is a class template. The compiler reserves the appropriate amount of memory based on the type of the elements and the arraySize. (Recall that a declaration which reserves memory is more properly known as a definition.) The arraySize must be an unsigned integer. To tell the compiler to reserve 12 elements for integer array c
, use the declaration
array< int, 12 > c; // c is an array of 12 int values
array
s can be declared to contain values of most data types. For example, an array
of type string
can be used to store character strings.