Variables & Constants

Test yourself on Variables & Constants with exam style questions, marked instantly.

Flashcards that come back just before you would forget them.

A revision plan that remembers what you know and shows what to do next.

See which topics you have nailed and which need another look.

Quiz yourself on Variables & ConstantsGet your flashcardsBuild my revision planTrack my progress

The Storage Boxes

Think of computer memory as a warehouse full of boxes. A variable is a labelled box where you can store data - and change what's inside whenever you want. The label (name) stays the same, but contents can change: "score = 10" then later "score = 15". A constant is a sealed box - once you put something in, it can never change. Use constants for things like PI = 3.14159 or VAT_RATE = 0.20.

A variable named score holds 0, then 10 after adding 10, then 25 after adding 15, so its value changes. Below it, a padlock marks three constants: PI is 3.14159, VAT_RATE is 0.20 and MAX_SIZE is 100. Their values do not change while the program runs.

The variable score changes from 0 to 10 to 25. The padlock marks constants, which are set once and never change. In OCR pseudocode a variable is written score = score + 10 and a constant is written const VAT_RATE = 0.2. Edexcel does not set a strict pseudocode style.

Variables vs Constants

Aspect Variable Constant
Value can change? Yes - can be reassigned No - fixed once declared
Use for Scores, counters, user input PI, VAT rate, fixed values
Naming convention camelCase or snake_case UPPER_CASE (often)
Example score = 100 const PI = 3.14159 (OCR style)

Deep Dive: Naming Rules

Good variable names:

  • Meaningful: playerScore not x
  • Start with letter or underscore, not number
  • No spaces - use camelCase or snake_case
  • No reserved words (if, while, for, etc.)
  • Case sensitive: Score ≠ score

Why use constants?

  • Prevents accidental changes
  • Makes code more readable
  • Easy to update in one place

Memory Trick

Variable = Varies - can change
Constant = Constant - stays the same (like a constant friend!)

Exam Tips

  • When to use each: Variable for things that change, constant for fixed values
  • Common mistake: Using a variable when a constant is more appropriate

Make this stick

Signing in gives access to all PrepWise features.

PrepWise is a trading name of A3M Quality Solutions Limited, registered in England and Wales, company number 14959172. Registered office: 202 Stroud Road, Gloucester, GL1 5LA. ICO registration ZC267069.