✏️ Explanatory Question
[Arrays]
Question:
What is the length of the array int arr[],
if its first index is x and the last index is y?
[Arrays]
Question:
What is the length of the array int arr[],
if its first index is x and the last index is y?
Answer:
Length = y - x + 1
Explanation:
Array length is calculated using:
Last Index - First Index + 1
Here:
Therefore:
Length = y - x + 1
Example:
If:
First index = 3
Last index = 7
Then:
Length = 7 - 3 + 1
= 5
The array elements are:
arr[3], arr[4], arr[5], arr[6], arr[7]
Total elements = 5
Conclusion:
Length = Last Index - First Index + 1