Setting Up Ranges with &&
The &&
operator also lets you set up a series of if else if else
statements, with each choice corresponding to a particular range of values. Listing 6.6 illustrates the approach. It also shows a useful technique for handling a series of messages. Just as a pointer-to-char
variable can identify a single string by pointing to its beginning, an array of pointers-to-char
can identify a series of strings. You simply assign the address of each string to a different array element. Listing 6.6 uses the qualify
array to hold the addresses of four strings. For example, qualify[1]
holds the address of the string "mud tug-of-war\n"
. The program can then use qualify[1
] as it would any other pointer to a string—for example, with ...
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.