In any programming language a data type tells the computer what kind of value is being stored and which operations are permitted. Mastery of the basic data types is essential for writing correct programs and for answering exam questions in the Cambridge IGCSE Computer Science syllabus.
All data types are stored as binary (base‑2) patterns. Understanding the link between size, binary/hexadecimal representation and overflow is a core part of Topic 1.1 – Number systems.
| Bits | Signed range (Two’s‑complement) | Unsigned range |
|---|---|---|
| 8 | -2⁷ … 2⁷‑1 (‑128 … 127) | 0 … 2⁸‑1 (0 … 255) |
| 16 | -2¹⁵ … 2¹⁵‑1 (‑32 768 … 32 767) | 0 … 65 535 |
| 32 | -2³¹ … 2³¹‑1 (‑2 147 483 648 … 2 147 483 647) | 0 … 4 294 967 295 |
Example – 8‑bit signed integer
Binary : 1111 1010
Two’s‑complement → invert bits (0000 0101) + 1 = 0000 0110 = 6
Result = -6
If an operation produces a value outside the defined range an overflow occurs; the value “wraps around” to the opposite end of the range.
| Data Type | Typical Size (bits) | Range / Values | Example in Pseudocode |
|---|---|---|---|
| Integer | 16 (default) or 32 | -215 … 215‑1 (16‑bit) -231 … 231‑1 (32‑bit) |
DECLARE age : INTEGER ← 17 |
| Real (Float) | 32 (single precision) | ≈ ±3.4 × 1038 with about 6‑7 decimal digits of precision | DECLARE price : REAL ← 12.99 |
| Boolean | 1 (often stored as a byte) | TRUE or FALSE | DECLARE isValid : BOOLEAN ← TRUE |
| Character | 8 (ASCII) or 16 (Unicode) | Any single printable symbol, e.g. ‘A’, ‘7’, ‘$’ | DECLARE grade : CHAR ← 'A' |
| String | 8 per character (ASCII) or 16 per character (Unicode) | Sequence of characters, length ≥ 0 | DECLARE name : STRING ← "Alice" |
| Array (List) | Size = element size × number of elements | Ordered collection of elements of the same type | DECLARE scores : ARRAY[1:10] OF INTEGER |
+, -, *, /, % (modulus).DECLARE x : INTEGER ← 120
x ← x + 10 ⟹ -126 (overflow)
ABS(a‑b) < 0.0001.DECLARE a : REAL ← 0.1 + 0.2 ⟹ 0.3000000119 (rounded)
TRUE or FALSE.AND, OR, NOT (short‑circuit in most languages).IF statements, WHILE loops and validation checks.LENGTH().fullName ← firstName + " " + lastNameLENGTH(myString)myString[3]myString[2:5]DECLARE name : ARRAY[lower:upper] OF type. The lower bound may be 0 or 1 – always state it explicitly.DECLARE Scores : ARRAY[1:10] OF INTEGER
value ← Scores[3] ⟹ third element
Scores[1] ← 100 ⟹ update first element
FOR loop:FOR i ← 1 TO LENGTH(Scores) DO
OUTPUT "Score", i, ":", Scores[i]
END FOR
DECLARE matrix : ARRAY[1:3,1:3] OF INTEGER
FOR r ← 1 TO 3 DO
FOR c ← 1 TO 3 DO
matrix[r,c] ← r*c ⟹ fill with multiplication table
END FOR
END FOR
Example – image size
DECLARE image : ARRAY[1:640*480] OF BYTE ⟹ 640 × 480 × 8 = 2 457 600 bits
→ 307 200 bytes → 300 KiB (≈0.3 MiB)
Run‑Length Encoding (RLE) – lossless compression
Original bytes : A A A A B B C C C
RLE output : (4,A) (2,B) (3,C)
Stored bits : (count 3 bits + symbol 8 bits) × 3 = 33 bits
RLE replaces consecutive identical values with a count‑value pair, reducing file size without losing information.
INTEGER for a sequence number, a CHAR[4] for a protocol identifier).BYTE or CHAR) and apply a key‑dependent transformation before transmission.BYTE) to meet memory constraints.INTEGER or CHAR).When a program stores data in a relational database, each column has a type that mirrors the programming language types.
| Programming type | Typical SQL column type |
|---|---|
| INTEGER | INT, SMALLINT, BIGINT |
| REAL | FLOAT, DOUBLE, DECIMAL(p,s) |
| CHAR | CHAR(n) |
| STRING | VARCHAR(n), TEXT |
| BOOLEAN | BOOLEAN (or TINYINT(1) in some DBMS) |
Choosing the correct column type prevents truncation, overflow, and unnecessary storage consumption.
TRUE = 1, FALSE = 0.AND → AND gateOR → OR gateNOT → NOT (inverter) gate(A AND NOT B) OR C:| A | B | C | Result |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
The FILE type is used only in I/O statements. A complete file‑handling block must contain OPEN, the I/O operation, and CLOSE.
DECLARE inFile : FILE
DECLARE outFile : FILE
DECLARE line : STRING
OPEN inFile FOR READ FROM "students.txt"
OPEN outFile FOR WRITE TO "report.txt"
WHILE NOT EOF(inFile) DO
READLINE inFile INTO line
WRITE outFile FROM line
END WHILE
CLOSE inFile
CLOSE outFile
Example of reading an array of integers from a file:
DECLARE scores : ARRAY[1:5] OF INTEGER
DECLARE i : INTEGER ← 1
OPEN inFile FOR READ FROM "scores.txt"
WHILE NOT EOF(inFile) AND i ≤ 5 DO
READ inFile INTO scores[i]
i ← i + 1
END WHILE
CLOSE inFile
Choosing the correct data type helps you write validation checks and produce reliable trace tables.
DECLARE age : INTEGER
READ age FROM keyboard
IF age >= 0 AND age <= 120 THEN
OUTPUT "Age accepted"
ELSE
OUTPUT "Invalid age – must be 0‑120"
END IF
When constructing a trace table, record:
INTEGER(price) or REAL(score).AND, OR, NOT.DECLARE Marks : ARRAY[0:4] OF INTEGER.OPEN, the I/O operation, and CLOSE.Basic data types – integers, reals, Booleans, characters, strings, and arrays – are the building blocks of every program. Knowing their size, range, binary representation, and appropriate operations enables you to store information correctly, manipulate it safely, and produce clear, exam‑ready pseudocode. These concepts link directly to the wider IGCSE topics of number systems, data storage & compression, data transmission, hardware, software, databases, and Boolean logic.
Create an account or Login to take a Quiz
Log in to suggest improvements to this note.
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.