Multiple choice

Given an array A[lb:ub]. The number of elements in this array is given by the formula

  1. ub - lb

  2. ub - lb + 1

  3. ub - lb -1

  4. lb - ub + 1

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

To find the total number of elements in an array with a given lower bound and upper bound, you subtract the lower bound from the upper bound and add 1 to include both endpoints.