1D Arrays & 1-Based Indexing

A One-Dimensional (1D) Array is a static data structure holding a fixed collection of elements of the same data type, referenced under a single identifier and accessed via an integer index.


1. Array Declaration in Cambridge Pseudocode

DECLARE <Identifier> : ARRAY[<LowerBound>:<UpperBound>] OF <DataType>

Key Declaration Rules:

  • Enclose the bounds inside square brackets [...].
  • Separate lower and upper bounds with a colon :.
  • Follow the declared bounds; [1:50] has 50 elements and [0:49] also has 50.
  • Specify the type with the OF keyword (e.g. OF INTEGER, OF STRING).

2. Accessing and Manipulating Array Elements

Individual elements are read or written using square bracket index notation:

DECLARE Grades : ARRAY[1:5] OF CHAR

// Direct assignment
Grades[1] <- 'A'
Grades[2] <- 'B'

// Iterative input
FOR i <- 1 TO 5
    INPUT Grades[i]
NEXT i

Exam Warning: Attempting to read or write to Grades[0] or Grades[6] triggers an Array Index Out of Bounds runtime error.

Declared bounds matter

Arrays can be declared with different lower bounds. ARRAY[0:4] contains five elements just as ARRAY[1:5] does. Use the declared bounds in loops; index zero is not universally forbidden. Our examples usually start at 1 for consistency.

AI Socratic Tutor

All-Access
Sign in or create an account. AI Tutor is an All-Access benefit.
Sign Up

Need guidance? Ask a question or use the hint below.

AI Socratic Tutor is an All-Access Benefit

Unlock step-by-step Socratic hints, algorithm trace table walkthroughs, and error diagnostics for every Cambridge exercise.

You're chatting with an AI tutor, not a person. AI can make mistakes, so double-check its answers.

Independent Practice: Sum an array

+30 XP

Read five integers into a one-dimensional array. Output their sum. Include negative values in your own test data.

Write a complete program. Read inputs in the stated order. Output only the requested results, one per line, without input prompts. Test with your own values before submitting.

solution.pseudo
All-Access Required

Interactive exercises for Module 2 and beyond require an active plan.

○ Mixed values
○ Last item matters
○ All negative