Data Types
A data type is the kind of value that a data item can hold. It tells you what a value actually is — a whole number, a number with a fraction, a true or false answer, or a piece of text — and therefore what you can sensibly do with it. Some types can be used together, such as an integer and a real in a sum, but adding a number to a piece of text does not work, because the two kinds of value are stored in completely different ways.
Primitive data types are the basic built-in types, such as integer, real, Boolean and character, from which structured data types can be built. A structured data type holds several values grouped together. A string is an example: it is a sequence built from characters, so "Kestrel" is really seven characters placed side by side.
| Primitive type | Kind of value it holds | Example |
|---|---|---|
| Integer | A whole number | 28 |
| Real | A number that can have a fractional part | 3.6 |
| Boolean | One of two values, True or False | True |
| Character | Exactly one character | 'Q' |
The type is not just a label. It decides how the value is stored in memory, how much memory it needs, and which operations are valid on it. Imagine a game stores your score of 8 as an integer: you can add the next level's 6 points and get a new total of 14. If the same 8 were stored as the string "8", joining it to "6" would give "86" instead of 14, because + would glue the text together rather than do arithmetic. Choosing the type to match the real data is what keeps a program's results accurate.
Edexcel GCSE Computer Science · Data Types