🗄️ Paper 1 · Topic 2: Data & Data Types
2.2a Variables, Constants & Data Types ✓ Free
Edexcel 1CP2 · GCSE Computer Science · ~12 min read · ✓ Free lesson
Notes
──
Video
──
Slides
──
Worksheet
──
Quiz

Variables

A variable is a named storage location in memory whose value can change during the execution of a program. Variables hold data that a program needs to process.

  • Each variable has a name (identifier), a data type, and a value
  • The value can be read or updated at any point in the program
  • Example: score = 0 — 'score' is the identifier, 0 is the value

Constants

A constant is a named value that is set once and cannot be changed during program execution.

  • Used for values that should never change (e.g., Pi = 3.14159, VAT = 0.20)
  • Makes code clearer and prevents accidental modification
  • Example: PI = 3.14159 — this value stays fixed throughout the program
FeatureVariableConstant
Value can change✓ Yes✗ No
Set at runtime✓ YesSet at program start
Prevents modification✓ Yes
Example usePlayer scorePi, VAT rate

Data Types

Every variable or constant has a data type which determines what kind of data it can store and how much memory it uses.

Data typeDescriptionExample
IntegerWhole numbers (positive, negative, zero)42, −7, 0
Real / FloatNumbers with a decimal point3.14, −0.5
BooleanTrue or False onlyTrue, False
CharacterA single character'A', '5', '!'
StringA sequence of characters (text)"Hello", "CSZone"

Why data types matter

  • Determines valid operations (you can add integers; you can concatenate strings)
  • Affects memory allocation
  • Prevents errors — storing a string where a number is expected causes a type error

Casting (Type Conversion)

Sometimes you need to convert between data types — called casting:

  • int("42") converts the string "42" to integer 42
  • str(42) converts integer 42 to string "42"
  • float("3.14") converts string to real number
Exam tip: Edexcel 1CP2 expects you to identify correct data types for given scenarios, state the difference between variables and constants, and explain why appropriate data types should be used. Remember: integers for counting, reals for measurements, Booleans for conditions.
⚠️ Common Mistakes
  • Confusing character (single char) with string (sequence of chars)
  • Saying constants "save memory" — they don't; the benefit is clarity and preventing errors
  • Using integer for data that can have decimal places (e.g., prices should be real/float)
  • Forgetting that Boolean only has two values: True or False
Video coming soon
Click slide or press arrow keys to navigate
✍️

Worksheet — 2.2a Variables, Constants & Data Types

8 Edexcel-style questions · instantly marked

Q1State the difference between a variable and a constant.[2]
✅ Mark scheme
A variable is a named storage location whose value can change during program execution [1]; a constant is a named value that is set once and cannot be changed during execution [1].
Q2Identify the most appropriate data type for each: (a) a person's age, (b) their name, (c) whether they are a member.[3]
✅ Mark scheme
(a) Integer [1]; (b) String [1]; (c) Boolean [1].
Q3Give one reason why constants are used instead of variables in programs.[1]
✅ Mark scheme
Any one: to prevent accidental modification of a fixed value [1]; to improve code readability (a meaningful name is more clear than a magic number) [1].
Q4What is the difference between an integer and a real (float) data type?[2]
✅ Mark scheme
An integer stores whole numbers only (no decimal point) [1]; a real/float stores numbers with decimal places [1].
Q5What is a Boolean data type? Give one example of when it would be used.[2]
✅ Mark scheme
A Boolean can only hold the value True or False [1]; e.g., to store whether a user is logged in (True/False) or whether a game is over [1].
Q6Explain what 'casting' means in programming and give one example.[2]
✅ Mark scheme
Casting is converting a value from one data type to another [1]; e.g., converting a string "42" to integer 42 using int("42") [1].
Q7What is the difference between a character and a string data type?[2]
✅ Mark scheme
A character stores a single symbol/letter/digit [1]; a string stores a sequence of characters (text of any length) [1].
Q8A programmer stores a product price as an integer. Identify the problem and suggest a better data type.[2]
✅ Mark scheme
Integer cannot store decimal places, so prices like £9.99 would be truncated/lost [1]; real/float should be used instead [1].
Topic Quiz
Q 1 of 15
You scored
out of 15
Click to reveal definition
🎉
Session complete!
TermDefinition
🎯

Mini Test — Variables, Constants & Data Types

Timed exam-style test.

← 2.1f Encoding, Images & SoundTopic 2Next: 2.2b Records as Data →