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, a pointer-to-
char that can be initialized to the address of a string. The program initializes
cities 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 ...