What is the length of an array when its first index is denoted by i and last…

2021

What is the length of an array when its first index is denoted by i and last index is denoted by j?

  1. A.

    length of an array = i + j

  2. B.

    length of an array = j − i

  3. C.

    length of an array = j − i + 1

  4. D.

    length of an array = j − i − 1

Attempted by 1114 students.

Show answer & explanation

Correct answer: C

To find the length of an array when the first index is i and the last index is j, we need to count the number of elements from i to j, inclusive. The formula is: length = j - i + 1. Explanation: The difference (j - i) gives the number of steps between the indices. Adding 1 accounts for the inclusion of both the first and last elements.

Explore the full course: Up Lt Grade Assistant Teacher 2025