Using a Two-Dimensional Array
Listing 5.20 incorporates an initialized two-dimensional array and a nested loop into a program. This time the program reverses the order of the loops, placing the column loop (city index) on the outside and the row loop (year index) on the inside. Also it uses a common C++ practice of initializing an array of pointers to a set of string constants. That is, cities
is declared as an array of pointers-to-char
. That makes each element, such as cities[0]
, a pointer-to-char
that can be initialized to the address of a string. The program initializes cities[0]
to the address of the "Gribble City"
string, and so on. Thus, this array of pointers behaves like an array of strings.
// nested.cpp -- nested ...
Get C++ Primer Plus 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.