7.3. Declaring arrays

arrays 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

arrays can be declared to contain values of most data types. For example, an array of type string can be used to store character strings.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.80.15