Learning Objectives
  • Explain the purpose of variables and constants in a program.
  • Declare variables and constants using Cambridge pseudocode.
  • Choose meaningful identifiers that communicate the purpose of stored data.
  • Trace how assignment changes the current value of a variable.
Key Terms
Variable
A named memory location whose stored value can change while a program is running.
Constant
A named value that is fixed for the whole program and must not be changed by assignment.
Identifier
The name given to a variable, constant, array, procedure or function.
Declaration
A statement that introduces an identifier and, for a variable, specifies its data type.
Assignment
Replacing the current value stored in a variable with the result of an expression.
Initialisation
Giving a variable its first known value before it is used.
Summary diagram
Summary Of The Main Ideas In This Lesson
Why Programs Need Named Storage

Programs process data that changes as instructions are executed. A variable provides a name for one item of data so later statements can read its current value or replace it. Without variables, a program could not remember input, intermediate results, counters or final answers.

The value belongs to the variable at a particular moment. If Total is assigned 20 and later assigned Total + 5, the new value becomes 25. The identifier remains the same, but the stored value changes. This distinction is essential when tracing code.

Variables should be declared before use. A declaration tells the reader and translator what kind of value the variable is intended to hold. In Cambridge pseudocode, the form is DECLARE identifier : data type.

Variables And Constants

A constant represents a value that should remain fixed, such as the number of months in a year or a tax rate provided by the question. Giving the value a name makes the program easier to read and reduces repeated unexplained numbers.

Cambridge pseudocode uses a constant declaration such as CONSTANT MaximumMark = 100. A constant should not appear on the left side of an assignment later in the program. If a value may change, it must be a variable instead.

Constants also improve reliability. If a fixed value must be changed during development, one declaration is edited rather than every occurrence of a literal value.

Meaningful Identifiers

A meaningful identifier describes the role of the item. StudentCount communicates more than C, and MaximumTemperature communicates more than X. Cambridge explicitly expects meaningful identifiers for variables, constants, arrays, procedures and functions.

An identifier should be concise but unambiguous. Names such as Total, AverageMark and IsValid are usually better than long sentences. Avoid choosing a name that suggests the wrong meaning, such as using Average for a total.

Consistent naming helps readers distinguish different kinds of data. A Boolean name often reads like a question or condition, for example IsFound or ContinueEntry. An array name is commonly plural, such as Marks or StudentNames.

Declaration, Initialisation And Assignment

Initialisation gives variables known starting values. Totals and counters normally start at zero. A maximum or minimum requires special care because an unsuitable starting value may produce a wrong answer.

The assignment arrow points from the expression to the variable. The right side is evaluated first, then its result replaces the old value on the left. Therefore Count <- Count + 1 is meaningful even though it is not a mathematical equation.

A variable must not be read before it has a known value. For example, Total <- Total + Price is unsafe unless Total was initialised earlier.

DECLARE StudentCount : INTEGER
DECLARE TotalCost : REAL
DECLARE IsComplete : BOOLEAN
CONSTANT MonthsInYear = 12

StudentCount <- 0
TotalCost <- 0.0
IsComplete <- FALSE
Tracing Changes In Values
Statement Value Of Score Before Value Of Score After
Score <- 10 Undefined 10
Score <- Score + 4 10 14
Score <- Score * 2 14 28
Score <- Score DIV 5 28 5
Worked Examples
Choosing Declarations

Question: Declare storage for a persons age, full name, account balance and whether the account is active.

  1. Age is a whole number, so use INTEGER.
  2. FullName may contain several characters, so use STRING.
  3. AccountBalance may contain a fractional part, so use REAL.
  4. IsActive has only TRUE or FALSE values, so use BOOLEAN.

Answer: DECLARE Age : INTEGER; DECLARE FullName : STRING; DECLARE AccountBalance : REAL; DECLARE IsActive : BOOLEAN.

Tracing An Assignment

Question: Total starts at 12. What is stored after Total <- Total + 8 and then Total <- Total DIV 5?

  1. The first assignment evaluates 12 + 8, so Total becomes 20.
  2. The second assignment performs integer division: 20 DIV 5 = 4.

Answer: The final value of Total is 4.

Examination Guidance
  • Use the assignment arrow rather than an equals sign when writing Cambridge pseudocode.
  • Declare each variable with an appropriate basic data type.
  • State that a constant cannot change during program execution.
  • Use identifiers that show purpose, not merely the type of the value.
  • In trace questions, use the old value on the right side before replacing it.
Common Mistakes
  • Treating assignment as a mathematical equality.
  • Using an undeclared variable.
  • Calling every named value a variable even when it is fixed.
  • Failing to initialise counters or totals.
  • Using identifiers such as A, B and X when the scenario supports clearer names.
Knowledge Check

1. What is a variable?

Answer: A named memory location whose value can change during execution.

2. What is a constant?

Answer: A named value that remains fixed throughout the program.

3. Why use meaningful identifiers?

Answer: They make the purpose of data and program units clear, improving readability and maintenance.

4. What does initialisation do?

Answer: It gives a variable its first known value.

5. What happens in Count <- Count + 1?

Answer: The old Count is increased by one and the result replaces it.