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 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.