🆓 Free Lesson · Paper 2 · Topic 8
8.1a Programming Concepts: Variables, Data Types & I/O
Cambridge IGCSE Computer Science 0478 · ~16 min read · ✓ Free

Variables and Constants

A variable is a named memory location that holds a value which can change during the program's execution. A constant is a named value that cannot change.

In Cambridge pseudocode, assignment uses the ← arrow:

score ← 0          // variable — can change
PI ← 3.14159        // constant — should not change
name ← "Alice"

Rules for identifier names

  • Must start with a letter
  • Can contain letters, digits, and underscores (no spaces)
  • Should be meaningful (e.g., totalScore not x)
  • Cambridge pseudocode is case-insensitive for keywords but names are case-sensitive

Data Types

Every variable has a data type that determines what kind of value it can hold and what operations can be performed on it.

Data TypeDescriptionExample
INTEGERWhole numbers (positive, negative, or zero)42, -7, 0
REALNumbers with a decimal point3.14, -0.5, 100.0
CHARA single character'A', '3', '!'
STRINGA sequence of characters"Hello", "CS0478"
BOOLEANLogical value — TRUE or FALSE onlyTRUE, FALSE
Important: In Cambridge pseudocode, strings use double quotes ("Hello") and characters use single quotes ('A'). The data type matters for operations — you cannot add an INTEGER to a STRING without converting it first.

Input and Output

Programs communicate with users through input (data coming in) and output (data going out).

// Input — get a value from the user:
INPUT name
INPUT score

// Output — display a value or message:
OUTPUT "Enter your name: "
OUTPUT "Hello, ", name
OUTPUT score

Combining output with variables

name ← "Alice"
score ← 95
OUTPUT "Player: ", name
OUTPUT "Score: ", score
OUTPUT "Player: " & name & " scored " & score

Casting (Converting) Data Types

Sometimes you need to convert between data types. Cambridge pseudocode uses built-in functions:

FunctionConverts toExample
INT(x)INTEGERINT(3.7) returns 3
REAL(x)REALREAL(5) returns 5.0
STRING(x)STRINGSTRING(42) returns "42"
CHAR_TO_NUM(c)INTEGER (ASCII code)CHAR_TO_NUM('A') returns 65
NUM_TO_CHAR(n)CHARACTERNUM_TO_CHAR(65) returns 'A'

Declaring Variables (structured pseudocode)

In some Cambridge mark schemes you may see variable declarations:

DECLARE score : INTEGER
DECLARE name : STRING
DECLARE temperature : REAL
DECLARE active : BOOLEAN
Exam tip: Always choose the most appropriate data type. A price should be REAL (has decimals). A count of students should be INTEGER. Whether a light is on or off is BOOLEAN.
⚠️ Common Mistakes
  • Using the wrong data type — e.g., storing age as REAL when INTEGER is correct
  • Putting double quotes around a character — 'A' is a CHAR, "A" is a STRING
  • Forgetting that BOOLEAN can only be TRUE or FALSE — not "yes"/"no"
  • Using = for assignment instead of ←
Video coming soon
Click slide or press arrow keys to navigate
✍️

Worksheet — Variables, Data Types & I/O

5 questions · 12 marks

Q1State the most appropriate data type for each of the following: (a) a student's exam score out of 100, (b) whether a user is logged in, (c) a product price, (d) a single letter grade. [4]
✅ Mark scheme
(a) INTEGER [1]; (b) BOOLEAN [1]; (c) REAL [1]; (d) CHAR [1]
Q2Write pseudocode to input a user's name and age, then output a message: "Hello [name], you are [age] years old." [3]
✅ Mark scheme
INPUT name [1]; INPUT age [1]; OUTPUT "Hello " & name & ", you are " & STRING(age) & " years old." [1]
Q3State the difference between a variable and a constant. [2]
✅ Mark scheme
A variable is a named memory location whose value can change during program execution [1]; a constant is a named value that is fixed and cannot be changed [1]
Q4What is the difference between a CHAR and a STRING? Give an example of each. [2]
✅ Mark scheme
CHAR holds exactly one character (e.g., 'A') [1]; STRING holds a sequence of zero or more characters (e.g., "Hello") [1]
Q5What would INT(7.9) return? What would REAL(5) return? [1]
✅ Mark scheme
INT(7.9) returns 7 (truncates, does not round) [0.5]; REAL(5) returns 5.0 [0.5] — accept either for full mark
Quiz — Programming Concepts
Q 1 of 8
Score
/ 8
Click to reveal
TermDefinition
🎯

Mini Test — Programming Concepts

10 minutes · mixed marks

← 7.3d Algorithm Efficiency Topic 8: Programming Next: 8.1b Selection →