8.5 Built-In Arrays

In Chapter 7, we used the array class template to represent fixed-size lists and tables of values. Here we present built-in arrays, which are also fixed-size data structures.

8.5.1 Declaring and Accessing a Built-In Array

To specify the type of the elements and the number of elements required by a built-in array, use a declaration of the form:


type arrayName[arraySize];

The compiler reserves the appropriate amount of memory. The arraySize must be an integer constant greater than zero. For example, to tell the compiler to reserve 12 elements for built-in array of ints named c, use the declaration


int c[12]; // c is a built-in array of 12 integers

As with array objects, you use the subscript ([]) operator to access the ...

Get C++ How to Program, 10/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.