Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
This Array bounds starting at zero or one worksheet is part of the IGCSE Computer Science 0478 — 8.2 Arrays journey. Print it as a booklet?
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1DECLARE Scores : ARRAY[0:29] OF INTEGER | AThe first index is 1 and the last is 30, so the array holds 30 elements | |
| 2DECLARE Scores : ARRAY[1:30] OF INTEGER | BDECLARE Names : ARRAY[1:20] OF STRING | |
| 3Stating the lower bound explicitly in the declaration shows whether the first element is at index 0 or 1 | CARRAY[0:30] holds 31 elements (0 to 30). For 30 elements starting at 0, use ARRAY[0:29]. Or use ARRAY[1:30] to start at 1. | |
| 4In an array with lower bound 0, the first element is read using index 0 | DOUTPUT Scores[0] | |
| 5DECLARE Marks : ARRAY[0:30] OF INTEGER // the student wants exactly 30 elements | EIndex 30 is out of range because the upper bound is 29. The last element is Marks[29], and the first is Marks[0]. | |
| 6DECLARE Marks : ARRAY[0:29] OF INTEGER OUTPUT Marks[30] | FThe first index is 0 and the last is 29, so the array holds 30 elements |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
ARRAY[1:30] — The number before the colon is the lower bound, the first index. ARRAY[1:30] starts at 1, ARRAY[0:29] starts at 0. Both hold 30 elements, so always state the lower bound.DECLARE Names : ARRAY[1:30] OF STRINGDECLARE Scores : ARRAY[0:29] OF INTEGERDECLARE Marks : ARRAY[0:29] OF INTEGER
OUTPUT Marks[0]DECLARE Marks : ARRAY[0:29] OF INTEGER
FOR Index ← 0 TO 29
OUTPUT Marks[Index]DECLARE Names : ARRAY[1:30] OF STRING
OUTPUT Names[30]