Introducing Arrays
An array is a data form that can hold several values all of one type. For example, an array can hold 60 type int values that represent five years of game sales data, 12 short values that represent the number of days in each month, or 365 float values that indicate your food expenses for each day of the year. Each value is stored in a separate array element, and the computer stores all the elements of an array consecutively in memory.
To create an array, you use a declaration statement. An array declaration should indicate three things:
The type of value to be stored in each element
The name of the array
The number of elements in the array
You accomplish this in C++ by modifying the declaration for a simple variable, adding ...
Get The Waite Group's C++ Primer Plus, Third 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.