|
|
|
|
|
|
|
In the first statement, 5 is stored into an array component. If counter is 0, 5 is stored into the first component of the array. If counter is 1, 5 is stored into the second place in the array, and so forth. |
|
|
|
|
|
|
|
|
In the second statement, an array component is selected by the expression number+1. The specific array component accessed is divided by 10 and checked to see if the remainder is nonzero. If number+1 is 0, the value in the first component is being tested; if number+1 is 1, the second place is tested; and so on. Figure 11-5 shows the indexing expression as a constant, a variable, and a more complex expression. |
|
|
|
|
|
|
|
|
Out-of-Bounds Array Indices |
|
|
|
|
|
|
|
|
the valid range of index values is 0 through 99. What happens if we execute the statement |
|
|
|
|
|
|
|
|
Figure 11-5
An Index as a Constant, a Variable, and an Arbitrary Expression |
|
|
|
|
|