Fundamentals

Variables

Variables are the building blocks of any program — they let you store, name and reuse data. Master how to declare, name and use variables (and constants) the CIE way.

3.1 What is a Variable?

A variable is a named storage location in a computer's memory that holds a value which can change while a program runs. Think of it as a labelled box — the label is the variable's name, and the contents are the value currently stored inside.

Key idea: The name of a variable stays the same, but the value inside it can change as the program runs. That's why it's called a variable!

Why do we use variables?

  • To store user input or calculated results for later use
  • To reuse values without re-typing them every time
  • To make code readable by giving meaningful names to data
  • To allow a program to react to changing data at run time

Here's a tiny example that stores and uses a value:

DECLARE Age : INTEGER
Age <- 15
OUTPUT "You are " + Age + " years old."

3.2 Declaring Variables

Before you can use a variable, you have to declare it. In CIE pseudocode this is done with the DECLARE keyword followed by the variable's name, a colon, and its data type.

Syntax

DECLARE <Name> : <Type>

Examples

DECLARE Score : INTEGER
DECLARE Price : REAL
DECLARE UserName : STRING
DECLARE IsReady : BOOLEAN

After a variable is declared, you can give it a value using the assignment operator <-:

DECLARE Score : INTEGER
Score <- 100
OUTPUT Score

Remember: Declaring a variable only creates the "box". It does not put anything inside — you must assign a value before using it.

3.3 Data Types

A data type tells the computer what kind of value a variable will hold. Choosing the right type keeps your program correct and efficient. These are the data types used in CIE pseudocode:

TypeStoresExample
INTEGERWhole numbers42, -7, 0
REALNumbers with decimals3.14, -0.5
STRINGText (in quotes)"Hello", "Bob"
CHARA single character'A', '7'
BOOLEANTrue or False onlyTRUE, FALSE
ARRAYA collection of values[1, 2, 3, 4]
DECLARE Age : INTEGER
DECLARE Temperature : REAL
DECLARE FirstName : STRING
DECLARE Initial : CHAR
DECLARE IsLoggedIn : BOOLEAN

Tip: Picking the right type matters! Storing an age as a STRING would stop you doing maths with it. Storing a price as an INTEGER would lose the decimal part.

3.4 Variable Naming Rules

Good variable names make your code easy to read and understand. CIE pseudocode (like most languages) has rules about what is and isn't allowed as a variable name.

The Rules

Must start with a letter (A–Z, a–z)
Can contain letters, digits and underscores _
Cannot contain spaces
Cannot be a reserved keyword (e.g. DECLARE, IF, OUTPUT)
Should be descriptive and meaningful
Are case-sensitive — Score and score are different

Valid vs Invalid Examples

Valid

  • Total_Score
  • Age
  • StudentName
  • Price1

Invalid

  • 2ndPlace (starts with digit)
  • Student Name (has space)
  • OUTPUT (keyword)
  • Total-Score (hyphen not allowed)

3.5 Constants

A constant is like a variable, but its value is set once when the program is written and can never change while the program runs. Use constants for values that should stay the same — like tax rates, conversion factors, or settings.

Syntax

CONSTANT <Name> <- <Value>

Examples

CONSTANT PI <- 3.14159
CONSTANT VAT_RATE <- 0.20
CONSTANT MAX_USERS <- 100

OUTPUT "Circumference: " + 2 * PI * Radius

Why use constants? If you ever need to change a value (say VAT goes from 20% to 22%), you only need to change it in one place. The rest of your code automatically uses the new value.

Variable vs Constant

FeatureVariableConstant
KeywordDECLARECONSTANT
Type needed?Yes (e.g. INTEGER)No — inferred from value
Value can change?Yes, any timeNo — fixed forever
Example useUser input, countersPI, tax rate, MAX_SIZE

3.6 Key Points Summary

Let's recap the most important ideas from this topic before you tackle the Question Bank.

A variable is a named storage location whose value can change.
Use the DECLARE keyword to create a variable: DECLARE Name : Type.
The assignment operator is <- (an arrow, not =).
Common types: INTEGER, REAL, STRING, CHAR, BOOLEAN, ARRAY.
Variable names must start with a letter, contain no spaces, and not be keywords.
Names are case-sensitive: Score and score are different.
Constants use CONSTANT Name <- Value and never change.
Always pick the most appropriate data type for the value you are storing.

Exam tip: In CIE exams, always write pseudocode with UPPERCASE keywords (DECLARE, OUTPUT, IF...) and use the <- arrow for assignment. Examiners deduct marks for using = instead of <-.

Question Bank

Answer all 12 questions, then submit to see your score.

Answered 0 / 12

Question 1Multiple Choice

What is a variable in programming?

Question 2True / False

In CIE pseudocode, the DECLARE keyword is used to create a new variable.

Question 3Multiple Choice

Which of the following is the correct way to declare a variable to store a person's name?

Question 4Multiple Choice

Which of these is a VALID variable name in CIE pseudocode?

Question 5True / False

Once a constant is declared, its value can be changed later in the program.

Question 6Multiple Choice

DECLARE X : INTEGER
X <- 42
OUTPUT "The answer is " + X

Question 7Multiple Choice

What is the assignment operator used in CIE pseudocode?

Question 8True / False

In CIE pseudocode, the variable names "Score" and "score" refer to the same variable.

Question 9Multiple Choice

Which data type is most appropriate for storing the value 3.14?

Question 10Multiple Choice

DECLARE Name : INTEGER
Name <- "Alice"
OUTPUT Name

Question 11True / False

A variable's value can change many times while a program is running.

Question 12Multiple Choice

What is the correct way to declare a constant named VAT_RATE with the value 0.20?