Arrays, Strings And Data Handling: Common Array And String Mistakes In Exams (Copy)
Common Array And String Mistakes In Exams
Why Examiners Love This Topic
- Array and string questions:
- Look simple
- Hide precision traps
- Most students lose marks without realising why
- Errors usually:
- Do not crash the logic
- Produce technically valid but wrong answers
- Examiner marking is unforgiving here
Category 1: Indexing Errors (NUMBER ONE MARK KILLER)
Mistake 1.1: Using Index 0 Instead Of Starting At 1
arr[0]
- Why wrong
- Indexing starts at 1 unless explicitly stated
- Result
- Out-of-range access
- Correct
arr[1]
Mistake 1.2: Accessing Index Beyond Declared Size
FOR i ← 1 TO n + 1
OUTPUT arr[i]
NEXT i
- Why wrong
arr[n + 1]does not exist
- Correct
FOR i ← 1 TO n
Mistake 1.3: Using Wrong Variable As Index
FOR i ← 1 TO n
OUTPUT arr[j]
NEXT i
- Why wrong
jnever changes
- Result
- Same element accessed repeatedly
Category 2: Loop Bound Errors With Arrays
Mistake 2.1: Hardcoding Loop Limits
FOR i ← 1 TO 10
- But array declared as:
DECLARE arr : ARRAY[1..n] OF INTEGER
- Why wrong
- Loop no longer matches array size
- Correct
FOR i ← 1 TO n
Mistake 2.2: Using LENGTH With Arrays
FOR i ← 1 TO LENGTH(arr)
- Why wrong
LENGTHapplies to strings, not arrays
- Correct
- Use known bounds (
n)
- Use known bounds (
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 AS Level Computer Science Full Scale Course
Category 3: Uninitialised Arrays And Strings
Mistake 3.1: Using Array Before Input Or Assignment
OUTPUT arr[i]
- No prior assignment
- Examiner view
- Undefined behaviour
- Fix
- Always populate first
Mistake 3.2: Using String Without Assignment
DECLARE name : STRING
OUTPUT name
- Value undefined
- Automatic logic error
Category 4: String Indexing Errors
Mistake 4.1: Accessing Character Outside String Length
text[LENGTH(text) + 1]
- Always invalid
Mistake 4.2: Forgetting Strings Are Indexed
IF text = "A" THEN
- Intended
- Check first character
- Correct
IF text[1] = "A" THEN
Mistake 4.3: Treating Characters As Numbers
IF text[i] > 5 THEN
- Invalid comparison
- Must compare characters to characters
Category 5: Direct Modification Of Strings (VERY COMMON)
Mistake 5.1: Trying To Modify A Character Directly
text[i] ← "X"
- Why wrong
- Strings are immutable at character level
- Correct approach
- Rebuild the string
newText ← ""
FOR i ← 1 TO LENGTH(text)
IF i = 3 THEN
newText ← newText & "X"
ELSE
newText ← newText & text[i]
ENDIF
NEXT i
text ← newText
Category 6: Confusing LENGTH Usage
Mistake 6.1: LENGTH Used On Arrays
LENGTH(arr)
- Wrong
- LENGTH is string-only
Mistake 6.2: Not Using LENGTH In String Traversal
FOR i ← 1 TO n
OUTPUT text[i]
NEXT i
nundefined- Correct
FOR i ← 1 TO LENGTH(text)
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 AS Level Computer Science Full Scale Course
Category 7: Logic Placement Errors
Mistake 7.1: IF Placed Outside Loop Instead Of Inside
FOR i ← 1 TO n
INPUT arr[i]
NEXT i
IF arr[i] > 0 THEN
count ← count + 1
ENDIF
- Why wrong
- Only last element checked
- Correct
FOR i ← 1 TO n
INPUT arr[i]
IF arr[i] > 0 THEN
count ← count + 1
ENDIF
NEXT i
Mistake 7.2: Updating Loop Variable Instead Of Array Element
FOR i ← 1 TO n
i ← i + 1
NEXT i
- Causes:
- Skipped elements
- Infinite loops
Category 8: Infinite Loops In Array/String Logic
Mistake 8.1: Missing Index Increment
WHILE index <= n DO
OUTPUT arr[index]
ENDWHILE
- Infinite loop
- Fix
index ← index + 1
Mistake 8.2: Condition Variable Never Changes
WHILE text[i] <> " " DO
OUTPUT text[i]
ENDWHILE
inever updated- Infinite 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 AS Level Computer Science Full Scale Course
Category 9: Mixing Array And String Logic Incorrectly
Mistake 9.1: Assigning Wrong Data Type
DECLARE ages : ARRAY[1..5] OF INTEGER
ages[1] ← "Ten"
- Invalid
- Data type mismatch
Mistake 9.2: Treating Character As Full String Carelessly
DECLARE ch : STRING
ch ← text[i]
- Acceptable logically
- But must be consistent in later comparisons
Category 10: Two-Dimensional Array Errors
Mistake 10.1: Swapping Row And Column Indices
table[col, row]
- Instead of
table[row, col]
Mistake 10.2: Incorrect Loop Nesting For Intended Logic
- Writing column-first traversal
- But describing row-based processing
Category 11: Output Mistakes
Mistake 11.1: Outputting Index Instead Of Value
OUTPUT i
- Intended
OUTPUT arr[i]
Mistake 11.2: Forgetting Final OUTPUT
- Computation done
- No output statement
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 AS Level Computer Science Full Scale Course
Examiner Red Flags (Instant Mark Loss)
- Out-of-range index
- LENGTH used on arrays
- Direct string modification
- IF placed incorrectly
- Infinite loop risk
- Uninitialised variables
Final Exam Safety Checklist
- Arrays populated before use
- Loop bounds match array size
- LENGTH used only with strings
- Strings rebuilt, not edited
- All WHILE loops update condition variables
- Every index stays in range
One-Line Rules To Memorise
- Indexing starts at 1
- LENGTH is string-only
- Strings are rebuilt
- IF placement matters
- Bounds discipline wins marks
