Hour 7. Storing Information in Arrays and Strings

What Is an Array?

An array is a collection of related data that all have the same data type. An array can be envisioned as a series of data storage locations. Each storage location is called an element of the array.

An array is declared by writing the data type and the array name followed by the number of elements the array holds inside square brace. Here’s an example:

long peaks[25];

The peaks array holds 25 long integers. This declaration causes the compiler to sets aside enough memory to hold all 25 elements. Because each long ...

Get Sams Teach Yourself C++ in 24 Hours, fifth edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.