📝 Paper 2 · 2.3 Programming Constructs
2.3.1 Variables, Constants and Assignment
Cambridge 9618 · International A Level Computer Science · ~10 min read
Notes
Video
Slides
Quiz
Worksheet

Variables

A variable is a named location in memory that stores a value which can change during program execution. Every variable in Cambridge 9618 pseudocode must be declared before use using the DECLARE keyword.

// Declaring variables with DECLARE
DECLARE age : INTEGER
DECLARE name : STRING
DECLARE price : REAL
DECLARE flag : BOOLEAN
DECLARE initial : CHAR

Assignment — the ← operator

In Cambridge 9618, assignment uses the ← operator (left-pointing arrow), not =. The = symbol is reserved for comparison (testing equality).

// Assign values using ←
age ← 17
name ← "Alice"
price ← 9.99
flag ← TRUE
initial ← 'A'

// Reassignment — overwrite previous value
age ← age + 1  // age becomes 18
price ← price * 1.2  // price becomes 11.988

Constants

A constant is a named value that is set once and cannot be changed during the program. Use CONSTANT (not DECLARE) and = (not ←) to define constants:

CONSTANT PI = 3.14159
CONSTANT MAX_SIZE = 100
CONSTANT SCHOOL_NAME = "Greenwood Academy"
CONSTANT VAT_RATE = 0.20
Variable
• Declared with DECLARE
• Value assigned with ←
• Value can change at runtime
• Example: DECLARE count : INTEGER
• Example use: loop counters, user inputs, running totals
Constant
• Declared with CONSTANT
• Value set with = (not ←)
• Value cannot change
• Example: CONSTANT PI = 3.14159
• Example use: mathematical constants, tax rates, maximum sizes

Why Use Constants?

  • Readability: price * VAT_RATE is clearer than price * 0.20
  • Maintainability: Changing the VAT rate only requires changing one CONSTANT line
  • Reliability: Prevents accidental modification of critical values

Scope — Local and Global

The scope of a variable determines where in the program it can be accessed.

Global Scope
DECLARE total : INTEGER
CONSTANT MAX = 100

Accessible anywhere in the program — in the main body, and inside procedures/functions.

Local Scope (inside a procedure)
DECLARE temp : INTEGER
DECLARE i : INTEGER

Declared inside a PROCEDURE or FUNCTION. Exists only while that block is executing. Cannot be accessed from outside.

DECLARE total : INTEGER  // global
total ← 0

PROCEDURE AddToTotal(value : INTEGER)
  DECLARE temp : INTEGER  // local — only exists inside this procedure
  temp ← value * 2
  total ← total + temp  // global can be accessed here
ENDPROCEDURE

// 'temp' does NOT exist here — local to AddToTotal

Arithmetic Operators

OperatorMeaningExampleResult
+Addition5 + 38
-Subtraction10 - 46
*Multiplication6 * 742
/Division (REAL result)7 / 23.5
DIVInteger quotient7 DIV 23
MODRemainder7 MOD 21
&String concatenation"Hi" & " there""Hi there"

Comparison Operators (used in conditions)

OperatorMeaningExample
=Equal toIF x = 5 THEN
<>Not equal toWHILE count <> 0 DO
<Less thanIF age < 18 THEN
>Greater thanIF score > 100 THEN
<=Less than or equalIF mark <= 40 THEN
>=Greater than or equalIF grade >= 7 THEN
Critical exam point: Cambridge 9618 uses ← for assignment and = for comparison. Writing x = 5 means "does x equal 5?" (comparison). Writing x ← 5 means "set x to 5" (assignment). Mixing these up is the most common error on Cambridge papers for this topic.
DIV vs /: 7 / 2 = 3.5 (REAL result). 7 DIV 2 = 3 (integer quotient, drops the remainder). 7 MOD 2 = 1 (the remainder). Checking whether a number is even: n MOD 2 = 0.
⚠️ Common Mistakes
  • Using = for assignment instead of (Cambridge will mark this wrong)
  • Using CONSTANT x ← value — CONSTANT uses =, not
  • Using a variable before declaring it with DECLARE
  • Trying to reassign a CONSTANT — PI ← 3.0 would be an error
  • Confusing DIV (integer quotient) with / (real division): 7 / 2 = 3.5, not 3
  • Confusing local/global scope — a local variable declared inside a procedure cannot be accessed outside it
✅ Notes completed!
Video coming soon
Click slide or press arrow keys to navigate

Worksheet — 2.3.1 Variables, Constants & Assignment

8 questions · Cambridge 9618 standard

Q1Write Cambridge 9618 pseudocode to declare a variable called temperature of type REAL and assign it the value 36.6.[2]
✅ Mark scheme
DECLARE temperature : REAL [1]; temperature ← 36.6 [1].
Q2State the difference between DECLARE and CONSTANT in Cambridge 9618. Write an example of each.[4]
✅ Mark scheme
DECLARE declares a variable whose value can change [1]; example e.g. DECLARE count : INTEGER [1]. CONSTANT declares a named value that cannot be changed [1]; uses = not ←, example CONSTANT MAX = 100 [1].
Q3What is the result of each of the following? (a) 15 DIV 4   (b) 15 MOD 4   (c) 15 / 4[3]
✅ Mark scheme
(a) 15 DIV 4 = 3 [1]; (b) 15 MOD 4 = 3 [1]; (c) 15 / 4 = 3.75 [1].
Q4Identify the error in each statement and write the corrected version.
(a) DECLARE total = 0
(b) CONSTANT rate ← 0.2
[4]
✅ Mark scheme
(a) Error: using = for assignment instead of ← [1]; corrected: DECLARE total : INTEGER (then assign with ←: total ← 0) [1]. (b) Error: using ← for constant instead of = [1]; corrected: CONSTANT rate = 0.2 [1].
Q5Explain the difference between local and global scope using an example.[4]
✅ Mark scheme
Global variable: declared outside procedures, accessible everywhere in the program [1]; example DECLARE total : INTEGER at top level [1]. Local variable: declared inside a procedure/function, only exists while that block runs [1]; example DECLARE temp : INTEGER inside a PROCEDURE body — cannot be accessed from main program [1].
Q6Give two reasons why using a CONSTANT for a value like VAT rate (0.20) is better than writing 0.20 directly in every calculation.[2]
✅ Mark scheme
Any 2 of: Readability — VAT_RATE is self-documenting, 0.20 is a magic number [1]; Maintainability — changing the rate only requires editing one CONSTANT line rather than every occurrence [1]; Reliability — prevents the value being accidentally overwritten [1].
Q7A program uses a 2D array Grid[1:4, 1:4] of INTEGER. Write pseudocode to: (a) initialise all elements to 0, (b) set diagonal elements (where row index = column index) to 1, (c) output the entire grid row by row. Use nested FOR loops throughout.[6]
✅ Mark scheme
(a) Nested FOR loops for row and column from 1 to 4: Grid[r,c] ← 0 [1]; (b) FOR r ← 1 TO 4: Grid[r,r] ← 1 [1]; (c) Nested FOR loops for r and c: OUTPUT Grid[r,c] (optionally with newline after each row) [1]; Correct CAIE pseudocode syntax throughout (DECLARE, FOR/NEXT or ENDFOR, array declaration) [1]; Array declaration: DECLARE Grid : ARRAY[1:4, 1:4] OF INTEGER [1]; Correct 2D indexing Grid[r,c] used throughout [1]. Award max 6.
Q8Explain the difference between a static array and a dynamic array. State one advantage and one disadvantage of each, and explain why CAIE pseudocode uses static arrays (with fixed bounds declared at compile time).[5]
✅ Mark scheme
Static array: size is fixed at declaration / compile time and cannot change during execution [1]; advantage: simple, predictable memory allocation — no overhead from resizing [1]; disadvantage: may waste memory if fewer elements are used than declared, or fail if more are needed than allocated [1]; Dynamic array: size can grow or shrink at runtime [1]; advantage: memory-efficient — only allocates what is needed; disadvantage: resizing incurs overhead (copying elements to a new block of memory) [1]; CAIE pseudocode uses static arrays because it is a teaching language designed for clarity — dynamic memory management adds complexity not needed for algorithm design at this level [1]. Award max 5.
Topic Quiz
Question 1 of 10
You scored
out of 10
Card 1 of 6
Click to reveal definition
🎉
All cards reviewed!
TermDefinition
🎯

Mini Test — 2.3.1 Variables & Constants

10 questions · 10 marks · 10 minutes

← 2.2.4 Abstract Data Types
41 of 82 · Cambridge 9618
2.3.2 Input/Output & Selection →