How many values can be held by an array A (-3:10, 5:12) ?
2013
How many values can be held by an array A (-3:10, 5:12) ?
- A.
91
- B.
119
- C.
112
- D.
104
Attempted by 88 students.
Show answer & explanation
Correct answer: C
Concept. When an array dimension is declared with explicit lower and upper bounds written as lower:upper, BOTH bounds are inclusive. The number of elements along that dimension (its extent) is therefore
extent = upper − lower + 1.
For a multi-dimensional array, the total number of storable values is the PRODUCT of the extents of every dimension.
Application. The declaration A(−3:10, 5:12) has two dimensions:
First dimension runs from −3 to 10, so its extent = 10 − (−3) + 1 = 14.
Second dimension runs from 5 to 12, so its extent = 12 − 5 + 1 = 8.
Total values = 14 × 8 = 112.
Cross-check. Counting the first dimension directly — −3, −2, −1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 — gives 14 distinct indices, and the second dimension 5, 6, 7, 8, 9, 10, 11, 12 gives 8 indices. The grid of index pairs has 14 × 8 = 112 cells, confirming the array holds 112 values.