SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
Cambridge IGCSE 0478 · Topic 8 · 8.1a

Variables, Data Types
& Constants

Data Types · Variables vs Constants · Casting · Sequence

CSZoneCambridge IGCSE Computer Science 0478
Data Types

Choosing the Right Type

Data TypeDescriptionExample
INTEGERWhole number42, -7, 0
REALNumber with decimal3.14, -0.5
STRINGText / sequence of characters"Hello", "AB12"
BOOLEANTRUE or FALSE onlyTRUE, FALSE
CHARSingle character'A', '3'
Choosing the right data type matters — storing an age as REAL wastes memory; storing a postcode as INTEGER is wrong
Variables vs Constants

Storing Values in Programs

Variable: a named storage location whose value can change during program execution. Declared with a name and data type.
Constant: a named storage location whose value is set once and cannot change during execution. Used for fixed values like PI or VAT_RATE.
DECLARE score : INTEGER // variable
CONSTANT PI ← 3.14159 // constant
score ← 85 // assign value
OUTPUT score * PI // use both
Sequence & Type Casting

Order of Execution & Conversions

Sequence: instructions execute one after another in the order written. No jumps unless a control structure (IF, loop) is used. The most basic programming construct.
// Type casting functions (Cambridge 0478)
INT("42") → 42 // string to integer
REAL("3.14") → 3.14 // string to real
STR(100) → "100" // integer to string

// Useful for combining INPUT (always string) with arithmetic
INPUT ageStr
age ← INT(ageStr)
OUTPUT age + 1
Exam Practice

Have a go at this question

Cambridge IGCSE 0478 style
A programmer needs to store a student's name, age, height (in metres), and whether they are enrolled. State the most appropriate data type for each piece of data and give a reason for one of your choices.
5 marks
Name: STRING [1]; Age: INTEGER [1]; Height: REAL [1]; Enrolled: BOOLEAN [1]. Reason: Height is REAL because it requires a decimal point (e.g. 1.72m) and INTEGER would lose the fractional part [1].
Key Takeaways

What to Remember

5 data types: INTEGER, REAL, STRING, BOOLEAN, CHAR — choose based on the data being stored
Variable: value can change; Constant: value fixed throughout the program (e.g. PI, VAT_RATE)
Sequence: instructions run top to bottom in order — the default execution model
Type casting: INT(), REAL(), STR() convert between types — INPUT always returns a string in Cambridge 0478