Explanation
Solution
To find the total number of elements in an array when the index range is given, we use the concepts of Upper Bound (UB) and Lower Bound (LB).
1. Definitions:
2. The Formula:
The number of elements (Length) is calculated by subtracting the lower bound from the upper bound and then adding 1 to include both endpoints.
3. Example for verification:
Suppose an array starts at index 10 and ends at index 20.
-
LB=10
-
UB=20
-
Length=20−10+1=11
If we simply did 20−10, we would get 10, which misses the first element. Therefore, adding 1 is necessary.
Final Answer:
The correct option is (c) Upper bound - Lower bound + 1.