Write pseudocode statements for: the declaration of variables

Published by Patrick Mutisya · 14 days ago

Cambridge A-Level Computer Science 9618 – 11.1 Programming Basics

11.1 Programming Basics

Objective

Write pseudocode statements for the declaration of variables.

Why Declare \cdot ariables?

In pseudocode a variable must be declared before it is used so that the computer knows:

  • The identifier (name) of the variable.
  • What type of data it can store (e.g., integer, real, Boolean).
  • Optionally, an initial value.

Common Data Types

  • Integer – whole numbers, e.g., \$-3\$, \$0\$, \$42\$.
  • Real – numbers with a fractional part, e.g., \$3.14\$, \$-0.001\$.
  • Boolean – logical values TRUE or FALSE.
  • Character – a single symbol, e.g., 'A', '9'.
  • String – a sequence of characters, e.g., "Hello".

Pseudocode Syntax for Declaration

The generic form is:

DECLARE <identifier> : <type> [← <initial‑value>]

Square brackets indicate that the initialisation part is optional.

Examples of \cdot ariable Declarations

VariableTypeInitial \cdot alue (optional)Pseudocode
ageInteger0DECLARE age : Integer ← 0
priceReal9.99DECLARE price : Real ← 9.99
is \cdot alidBooleanFALSEDECLARE is \cdot alid : Boolean ← FALSE
gradeCharacter'A'DECLARE grade : Character ← 'A'
nameString""DECLARE name : String ← ""

Step‑by‑Step Procedure for Declaring \cdot ariables

  1. Identify the purpose of each variable.
  2. Choose an appropriate data type.
  3. Write the DECLARE statement using the syntax above.
  4. If a sensible starting value exists, include it after the arrow ().
  5. Place all declarations at the beginning of the algorithm or in a dedicated section.

Common Pitfalls

  • Omitting the type – the compiler cannot infer the type in strict pseudocode.
  • Using a name that conflicts with a reserved word (e.g., IF, WHILE).
  • Assigning an initial value that does not match the declared type.

Suggested diagram: Flow of an algorithm showing a “Variable Declaration” block before the main processing steps.