Arrays, Records & Data Handling: One-Dimensional Array Declaration And Indexing (Copy)
One-Dimensional Array Declaration And Indexing (Cambridge Standard – O Level 2210 + IGCSE 0478)
Purpose Of One-Dimensional Arrays In Cambridge Pseudocode
- One-dimensional arrays are used to:
- Store multiple values of the same data type
- Allow efficient processing using loops
- Cambridge tests arrays to assess:
- Correct declaration
- Safe indexing
- Integration with loops, selection, procedures, and functions
- Arrays are central to:
- Pre-release material
- Section B modifications
- Trace table questions
What Cambridge Means By A One-Dimensional Array
- A one-dimensional array is:
- A list of values
- Stored under a single variable name
- Accessed using an index
- All elements:
- Must be of the same data type
- Index:
- Identifies the position of each element
Core Array Declaration Structure (Cambridge Standard)
- DECLARE arrayName[lowerBound:upperBound] : dataType
Key Declaration Rules
- DECLARE keyword is mandatory
- arrayName:
- Must be meaningful
- lowerBound and upperBound:
- Define valid index range
- dataType:
- Must match stored values
Example Declarations
- DECLARE marks[1:30] : INTEGER
- DECLARE names[1:20] : STRING
- DECLARE prices[0:9] : REAL
- DECLARE present[1:50] : BOOLEAN
Indexing System Used By Cambridge
- Cambridge allows:
- Any valid lower bound (0 or 1 most common)
- The index range is:
- Explicitly defined in the declaration
- Indexing is:
- Inclusive of both bounds
Example Index Ranges
| Declaration | Valid Index Values |
|---|---|
| marks[1:5] | 1, 2, 3, 4, 5 |
| data[0:9] | 0 to 9 |
| scores[5:10] | 5 to 10 |
Examiner Focus
- Loop boundaries must:
- Match array bounds exactly
- Any mismatch:
- Leads to out-of-range access
- Causes mark loss
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Accessing Array Elements (Indexing Syntax)
Standard Access Format
- arrayName[index]
Examples
- marks[1]
- names[i]
- prices[count]
Assignment To Array Elements
- marks[3] ← 75
- names[1] ← “Ali”
Reading From Array Elements
- total ← total + marks[i]
- OUTPUT names[index]
Using Arrays With FOR Loops (Most Tested Pattern)
Standard Traversal Pattern
- FOR i ← lowerBound TO upperBound
- PROCESS arrayName[i]
- ENDFOR
Example
- total ← 0
- FOR i ← 1 TO 30
- total ← total + marks[i]
- ENDFOR
Examiner Expectations
- Loop variable:
- Matches array index type
- Loop boundaries:
- Match declared bounds
- No hardcoded values if bounds are known
Common Array Indexing Errors (High-Risk)
Error 1: Out-Of-Bounds Index
- Accessing marks[31] when declared [1:30]
Error 2: Incorrect Loop Start Or End
- FOR i ← 0 TO 29
- marks[i]
- ENDFOR
- Invalid if array declared [1:30]
Error 3: Using Wrong Index Variable
- FOR i ← 1 TO 10
- total ← total + marks[j]
- ENDFOR
- j not controlled by loop
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Inputting Values Into One-Dimensional Arrays
Standard Input Pattern
- FOR i ← lowerBound TO upperBound
- INPUT arrayName[i]
- ENDFOR
Example
- FOR i ← 1 TO 20
- INPUT names[i]
- ENDFOR
Examiner Expectations
- INPUT occurs inside loop
- One value per iteration
- Array filled sequentially
Outputting Values From Arrays
Standard Output Pattern
- FOR i ← lowerBound TO upperBound
- OUTPUT arrayName[i]
- ENDFOR
Example
- FOR i ← 1 TO 10
- OUTPUT marks[i]
- ENDFOR
Arrays And Selection Logic
Conditional Processing Of Arrays
- FOR i ← 1 TO 30
- IF marks[i] >= 50 THEN
- passCount ← passCount + 1
- ENDIF
- IF marks[i] >= 50 THEN
- ENDFOR
Examiner Focus
- Selection does not control iteration
- Loop runs full range
- IF filters processing
Arrays And Accumulators
Correct Accumulator Use
- sum ← 0
- FOR i ← 1 TO n
- sum ← sum + values[i]
- ENDFOR
Common Accumulator Errors
- Initialising accumulator inside loop
- Using array index incorrectly
- Forgetting to initialise accumulator
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Arrays And Trace Tables
How Arrays Appear In Trace Questions
- Trace tables often include:
- Index variable
- Current array element
- Updated accumulators or counters
Trace Example Concept
- FOR i ← 1 TO 3
- total ← total + marks[i]
- ENDFOR
Trace variables:
- i
- marks[i]
- total
Common Trace Errors
- Skipping first element
- Stopping one iteration early
- Using incorrect index values
Arrays In Pre-Release Material
- Pre-release tasks frequently:
- Store data in arrays
- Process arrays using loops
- You must:
- Respect declared array size
- Never exceed bounds
- Use correct index variable
Arrays In Section B Modifications
- Section B commonly asks to:
- Add validation to array input
- Process subset of array
- Ignore invalid entries
- Safe strategy:
- Add IF inside loop
- Do not change array bounds
Example Modification
Original:
- FOR i ← 1 TO 30
- total ← total + marks[i]
- ENDFOR
Modified:
- FOR i ← 1 TO 30
- IF marks[i] >= 0 AND marks[i] <= 100 THEN
- total ← total + marks[i]
- ENDIF
- IF marks[i] >= 0 AND marks[i] <= 100 THEN
- ENDFOR
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Illegal Array Practices (Guaranteed Mark Loss)
- Accessing out-of-range index
- Using undeclared arrays
- Mixing data types in array
- Modifying loop index manually
- Ignoring declared bounds
- Assuming arrays auto-resize
Best-Practice Array Strategy For Paper 2
- Declare arrays clearly
- Match loop bounds exactly
- Use meaningful index variables
- Initialise accumulators correctly
- Add selection inside loops when needed
- Respect pre-release constraints
Final Quality Checklist
- Array declared correctly
- Bounds clearly defined
- Index used safely
- Loop boundaries correct
- No out-of-range access
- Logic traceable
Final Lock-In Rules
- Arrays store same-type data
- Index range is fixed and inclusive
- Loop boundaries must match array bounds
- Most array errors are boundary errors
- Clean array logic = high Paper 2 accuracy
