Practice question · Select all that apply
Let a be the list 3, 1, 4, 1, 5 with zero-based indexing. Select every TRUE statement.
Hints
- Write the indices 0..4 above the values before judging anything.
- One option uses an index that does not exist at all.
Show the answer
- A. the length of a is 5
- C. a[0] is 3
- E. a[4] is 5
Why
a[0] = 3, a[2] = 4 (not 1), the length is 5, a[4] = 5, and a[5] is out of bounds rather than 5. the second option is tempting precisely because the value 5 does appear in the list, but not at that index.
Practise Arrays and Lists
The app has 5 more questions on this lesson, and keeps your place in the course. Mathematics I is free to start.
More questions on Arrays and Lists
- Arrays are indexed from 0, so a list of length 5 has valid indices 0 to 4 and a[5] is an error. Why has this…
- A list has length 5 and uses zero-based indexing. Sort each access.
- Appending to a dynamic array is described as O(1) amortised, even though some appends copy the entire array.…
- Match each array operation to what it does.
- A list b holds seven values. A loop runs i from 0 to 7 inclusive and reads b[i] each time. How many of those…