1D arrays, 2D arrays, records, and how data structures appear in programs. Jun 2022 Q5(a)(i)/(ii) tested arrays directly.
Indexing typically starts at 0 in most languages. (Jun 2022 Q5(a)(i): "Array" or "List" both accepted. Q5(a)(ii): colours[1] = "Yellow".)
| Term | Definition |
|---|---|
| 1D array | |
| 2D array |
| Point | Detail |
|---|---|
| Record | |
| Arrays vs records | |
| Array of records | |
| Files |
| Data type | Example |
|---|---|
| Integer | |
| Real/Float | |
| Boolean | |
| String | |
| Character |
Choosing the wrong data type causes bugs — e.g. storing "42" as a string means you cannot do arithmetic on it.
What type of data structure stores a collection of items of the same data type, accessed by index?
An array is defined as: colours = ["Red", "Green", "Blue", "Yellow", "Purple"]
What is the value of colours[1]? And what index does "Purple" have? (2 marks)
Explain the difference between an array and a record as data structures. (2 marks)
A program needs to store whether a light switch is on or off. Which data type is most appropriate?