2. Variables & Types
Docs / Pseudocode / Variables & Types
CAIE 0478 & 9618 Variables & Types

2. Variables, Constants & Data Types

Cambridge pseudocode variable declarations, INTEGER, REAL, CHAR, STRING, BOOLEAN, DATE data types, CONSTANT definitions, and arrow (<-) assignments.

All variables must be declared using DECLARE with an explicit data type. Constants use CONSTANT. The assignment operator is <-.

Data Types

Data Type

Description

Literal Examples

INTEGER

A whole number

5, -3

REAL

A number with a fractional part

4.7, 0.3, -4.0, 0.0

CHAR

A single character

'x', 'C', '@'

STRING

A sequence of zero or more characters

"Hello", ""

BOOLEAN

Logical values

TRUE, FALSE

DATE

A valid calendar date

dd/mm/yyyy

Variable & Constant Declarations

PSEUDOCODE Run in Sandbox
// runnable
DECLARE Counter : INTEGER
DECLARE TotalToPay : REAL
DECLARE GameOver : BOOLEAN
DECLARE Initial : CHAR
DECLARE StudentName : STRING

// Comma-separated declarations are also supported per exam mark schemes
DECLARE Low, High, Mid, Target : INTEGER

CONSTANT HourlyRate = 6.50
CONSTANT DefaultText = "N/A"

Assignments

PSEUDOCODE Run in Sandbox
// runnable
// Assignment demo
DECLARE Counter : INTEGER
DECLARE TotalToPay, NumberOfHours : REAL
CONSTANT HourlyRate = 6.50
NumberOfHours <- 4
// The assignment operator is <-
Counter <- 0
Counter <- Counter + 1
TotalToPay <- NumberOfHours * HourlyRate
OUTPUT TotalToPay

Identifier Rules

  • Can contain letters (A-Z, a-z), digits (0-9), and underscore (_)
  • Must start with a letter, not a digit
  • Should be considered case insensitive
  • Keywords must never be used as variable names
  • Use descriptive names (e.g. NumberOfPlayers) — single letters are acceptable for loop conventions (e.g. i, j for array indices)