DECLARE statements, choose the appropriate Cambridge data type, initialise where required, and apply the correct scope rules.In the Cambridge A‑Level Computer Science (9618) exam every algorithm must begin with a clear declaration of every identifier that will be used. Declaring a variable tells the computer:
| Type | Typical Range / Description | Exam‑language equivalents |
|---|---|---|
| INTEGER | Whole numbers, usually –2 147 483 648 … 2 147 483 647 (32‑bit signed) | Java int, Python int, VB Integer |
| REAL | Numbers with a fractional part; single‑precision (≈ ±3.4 × 10³⁸) | Java float, Python float, VB Single |
| BOOLEAN | Logical values TRUE or FALSE |
Java boolean, Python bool, VB Boolean |
| CHARACTER | Single symbol, e.g. ‘A’, ‘9’, ‘$’ | Java char, Python str (length 1), VB Char |
| STRING | Sequence of characters, e.g. “Hello World” | Java String, Python str, VB String |
| CONST | Constant value that cannot be changed after initialisation | Java final, Python convention (uppercase name), VB Const |
| ARRAY | Ordered collection of elements of the same type | Java int[], Python list, VB Integer() |
| RECORD | Structure containing fields of different types (Cambridge term “record”) | Java class, Python dict/custom class, VB Type … End Type |
The Cambridge specification uses a language‑independent form. The generic pattern is:
DECLARE <identifier> : <TYPE> [← <initial‑value>]
[ ] denote an optional part.← is the **initialisation operator** – it may be used only in the declaration block. All later assignments also use ←, but the exam marks a loss of marks if a variable is used before it has been initialised.| Exam language | Declaration example |
|---|---|
| Java | int age = 0; |
| Python | age = 0 # type inferred as int |
| Visual Basic | Dim age As Integer = 0 |
_. They must start with a letter.totalScoretotal_scoreIF, FOR, WHILE, END, DECLARE, TRUE, FALSE.| Identifier | TYPE | Initial value | Pseudocode | Java | Python | VB |
|---|---|---|---|---|---|---|
| age | INTEGER | 0 | DECLARE age : INTEGER ← 0 |
int age = 0; |
age = 0 |
Dim age As Integer = 0 |
| price | REAL | 9.99 | DECLARE price : REAL ← 9.99 |
float price = 9.99f; |
price = 9.99 |
Dim price As Single = 9.99 |
| isValid | BOOLEAN | FALSE | DECLARE isValid : BOOLEAN ← FALSE |
boolean isValid = false; |
isValid = False |
Dim isValid As Boolean = False |
| grade | CHARACTER | 'A' | DECLARE grade : CHARACTER ← 'A' |
char grade = 'A'; |
grade = 'A' |
Dim grade As Char = "A" |
| name | STRING | "" (empty) | DECLARE name : STRING ← "" |
String name = ""; |
name = "" |
Dim name As String = "" |
| MAX_STUDENTS | CONST INTEGER | 30 | DECLARE MAX_STUDENTS : CONST INTEGER ← 30 |
final int MAX_STUDENTS = 30; |
MAX_STUDENTS = 30 # convention: upper‑case constant |
Const MAX_STUDENTS As Integer = 30 |
| scores | ARRAY[1..30] OF INTEGER | — | DECLARE scores : ARRAY[1..30] OF INTEGER |
int[] scores = new int[30]; |
scores = [0]*30 |
Dim scores(30) As Integer |
| student | RECORD | — | DECLARE student : RECORD
name : STRING
age : INTEGER
grade: CHARACTER
END RECORD |
class Student {
String name;
int age;
char grade;
} |
student = {'name':'', 'age':0, 'grade':''} |
Type Student
name As String
age As Integer
grade As Char
End Type |
DECLARE statement using the exact Cambridge syntax.←.DECLARE must specify a Cambridge type (INTEGER, REAL, …).DECLARE IF : BOOLEAN is illegal.DECLARE count : INTEGER ← "0".FOR i ← 1 TO 10
DECLARE total : INTEGER ← 0 ← ❌ local to the loop
END FOR
← total ← total + i ← error – total out of scope
TRUE or FALSE are allowed.| ✅ Item | What to Verify |
|---|---|
| All identifiers declared before first use | Search the algorithm for any variable that appears without a preceding DECLARE. |
| Correct Cambridge TYPE | INTEGER, REAL, BOOLEAN, CHARACTER, STRING, CONST, ARRAY, RECORD – matches the intended data. |
| Initial value matches TYPE | Numbers for INTEGER/REAL, TRUE/FALSE for BOOLEAN, quotes for CHARACTER/STRING. |
| No reserved words used as identifiers | Check against the list: IF, THEN, ELSE, FOR, WHILE, END, DECLARE, TRUE, FALSE, etc. |
| Scope is appropriate | Global only when needed by more than one sub‑algorithm; otherwise declare locally. |
Constants declared with CONST |
All values that never change (e.g., MAX_STUDENTS) use the CONST keyword. |
| Declaration block placed at the very start | First lines of the algorithm should be the DECLARE statements, optionally under a heading “Variable Declaration”. |
Exam Prompt (Cambridge style):
Write a pseudocode algorithm calledCALCULATE_AVERAGEthat:Use appropriate declarations, initialise variables, and observe correct scope.
- Reads the number of students
n(1 ≤ n ≤ 30).- For each student, reads the integer
mark(0 – 100) and stores it in an arraymarks.- Calculates the average (a REAL value) of the marks.
- Outputs the average to two decimal places.
Solution (highlighting declarations):
ALGORITHM CALCULATE_AVERAGE
/*--- Variable Declaration Block ---*/
DECLARE n : INTEGER
DECLARE i : INTEGER ← 0
DECLARE sum : INTEGER ← 0
DECLARE average : REAL ← 0.0
DECLARE marks : ARRAY[1..30] OF INTEGER
/*--- Input ---*/
OUTPUT "Enter number of students (1‑30): "
INPUT n
/* n is guaranteed to be within range by the question */
/*--- Process ---*/
FOR i ← 1 TO n
OUTPUT "Enter mark for student ", i, ": "
INPUT marks[i]
sum ← sum + marks[i]
END FOR
average ← sum / n /* division yields REAL */
OUTPUT "Average mark = ", average:2 /* 2 decimal places */
END ALGORITHM
DECLARE statements in pseudocode and translate them into Java, Python or VB where required.Create an account or Login to take a Quiz
Log in to suggest improvements to this note.
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.