7.2 array
s
An array
is a contiguous group of memory locations that all have the same type. To refer to a particular location or element in the array
, we specify the name of the array
and the position number of the particular element in the array
.
Figure 7.1 shows an integer array
called c
that contains 12 elements. You refer to any one of these elements by giving the array
name followed by the particular element’s position number in square brackets ([]
). The position number is more formally called a subscript or index (this number specifies the number of elements from the beginning of the array
). The first element has subscript 0 (zero) and is sometimes called the zeroth element. Thus, the elements of array
c
are c[0]
(pronounced “c
sub zero”), ...
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.