⚡ Quick Review: The 5 Primitive Data Types
- INTEGER: Positive or negative whole numbers (e.g.
42,-7,0). - REAL: Numbers with fractional or decimal components (e.g.
3.14159,-0.5). - CHAR: A single character enclosed in single quotes (e.g.
'Y','N','9'). - STRING: A sequence of zero or more characters in double quotes (e.g.
"Cambridge",""). - BOOLEAN: Logical truth values: strictly
TRUEorFALSE.
In this deep dive:
- ➔ 1. The 5 Standard Cambridge Primitive Data Types
- ➔ 2. INTEGER vs. REAL: Precision & Division Rules
- ➔ 3. CHAR vs. STRING: Literals, Memory & Indexing
- ➔ 4. Type Conversion Routines (INT, NUM_TO_STRING, STRING_TO_NUM)
- ➔ 5. User-Defined Composite Types (A-Level 9618 TYPE & ENUM)
- ➔ 6. Interactive Exam Practice: Type Identification & Casting
1. The 5 Standard Cambridge Primitive Data Types
In Cambridge IGCSE (0478), O-Level (2210), and International A-Level (9618), every variable must be declared with a strict data type before use. Selecting the wrong data type is one of the most frequent mark-loss triggers in Paper 2.
| Data Type | Cambridge Keyword | Exam Definition & Use Case | Example Literals | Paper 2 Common Pitfall |
|---|---|---|---|---|
| Integer | INTEGER |
Whole numbers used for counters, array indices, and quantities. | 0, 15, -230 |
Do not use for averages or prices (fractions get lost). |
| Real / Float | REAL |
Numbers with decimal/fractional parts for money, weights, averages. | 3.14, 0.0, -12.75 |
Do not use FLOAT; Cambridge only awards marks for REAL. |
| Character | CHAR |
A single keystroke, letter, digit, or symbol enclosed in single quotes. | 'A', 'm', '#', '5' |
Do not use double quotes. "A" is treated as a STRING. |
| String | STRING |
A sequence of zero or more characters enclosed in double quotes. | "PseudoStudio", "", "0123" |
Do not perform arithmetic on numeric strings without conversion. |
| Boolean | BOOLEAN |
Logical truth flag used for loop guards and validation checks. | TRUE, FALSE |
Cambridge requires uppercase TRUE/FALSE, not 1/0. |
2. INTEGER vs. REAL: Precision & Division Rules
Understanding when a calculation results in an INTEGER versus a REAL is essential for trace tables and loop logic. Cambridge pseudocode defines three distinct division operators:
/):
Always yields a REAL result, even if both operands are whole numbers. For example, 10 / 4 = 2.5, and 8 / 2 = 4.0.
DIV):
Divides two integers and returns only the whole number quotient, discarding any remainder. For example, 10 DIV 4 = 2.
MOD):
Calculates the integer remainder left over after integer division. For example, 10 MOD 4 = 2, and 15 MOD 2 = 1 (used for odd/even tests).
DECLARE TotalMarks : INTEGER
DECLARE StudentCount : INTEGER
DECLARE ClassAverage : REAL
TotalMarks ← 275
StudentCount ← 8
// Must assign to a REAL variable to prevent truncation:
ClassAverage ← TotalMarks / StudentCount
OUTPUT "Class average is: ", ClassAverage // Outputs 34.375
3. CHAR vs. STRING: Literals, Memory & Indexing
While both data types store textual data, Cambridge treats them distinctly in memory and syntax rules:
| Criteria | CHAR (Character) |
STRING (String) |
|---|---|---|
| Length | Exactly 1 character fixed | Variable length (0 to N characters) |
| Quote Delimiter | Single quotes: 'X' |
Double quotes: "X" |
| Empty State | Invalid (cannot be empty) | Valid: empty string "" with length 0 |
| Indexing | Atomic scalar value | 1-based character position access: MyStr[1] |
4. Type Conversion Routines (INT, NUM_TO_STRING, STRING_TO_NUM)
Real-world programs and Cambridge Paper 2 questions frequently require converting data from one type to another (such as converting string user input from an INPUT prompt into a numeric value for calculations):
// 1. INT(x): Converts REAL to INTEGER by truncating the decimal part
DECLARE DecVal : REAL
DECLARE IntVal : INTEGER
DecVal ← 8.79
IntVal ← INT(DecVal) // IntVal becomes 8
// 2. STRING_TO_NUM(s): Converts a numeric string into a number
DECLARE InputText : STRING
DECLARE ParsedNum : REAL
InputText ← "45.5"
ParsedNum ← STRING_TO_NUM(InputText) // ParsedNum becomes 45.5
// 3. NUM_TO_STRING(n): Converts a number into a formatted text string
DECLARE ResultStr : STRING
ResultStr ← NUM_TO_STRING(120) // ResultStr becomes "120"
5. User-Defined Composite Types (A-Level 9618 TYPE & ENUM)
At Cambridge International A-Level (9618 Paper 3), primitive types are combined into structured User-Defined Data Types using the TYPE ... ENDTYPE block:
// Record Structure: Groups multiple fields of differing types
TYPE StudentRecord
DECLARE StudentID : INTEGER
DECLARE StudentName : STRING
DECLARE ExamScore : REAL
DECLARE HasPassed : BOOLEAN
ENDTYPE
// Declaring a variable of the composite record type:
DECLARE Candidate1 : StudentRecord
Candidate1.StudentID ← 10482
Candidate1.StudentName ← "Amina"
Candidate1.ExamScore ← 88.5
Candidate1.HasPassed ← TRUE
// Enumerated Type (ENUM): Defines a set of allowed values
TYPE DayOfWeek = (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday)
DECLARE Today : DayOfWeek
Today ← Friday
Interactive Exam Practice: Data Type Identification
Exam Question: A student inputs an hourly wage as a string ("18.50") and hours worked as an integer (40). Write the algorithm to convert the wage string to a REAL, calculate the total gross pay, determine if overtime applies (BOOLEAN flag if hours > 35), and output the formatted summary.
Hover or tap the black box to reveal the model solution. Click Run Code to test it live!
DECLARE WageInput : STRING DECLARE HourlyRate : REAL DECLARE HoursWorked : INTEGER DECLARE GrossPay : REAL DECLARE IsOvertime : BOOLEAN WageInput ← "18.50" HoursWorked ← 40 // Convert string to real numeric value HourlyRate ← STRING_TO_NUM(WageInput) GrossPay ← HourlyRate * HoursWorked IF HoursWorked > 35 THEN IsOvertime ← TRUE ELSE IsOvertime ← FALSE ENDIF OUTPUT "Gross Pay: $", GrossPay OUTPUT "Overtime Qualified: ", IsOvertime
📝 Practice Data Type Exam Questions
Test your data type mastery with interactive Paper 2 coding challenges and dry-run trace table questions.