9618 AS Computer Science
Data types allow programming languages to provide different classifications for items of data, so they can be used for different purposes. For example, integers are discrete whole numbers used for counting and indexing, whereas real numbers can be used to provide accurate measurements!
A data type is a classification of data into groups according to the kind of data they represent. Computers use different data types to represent different types of data in a program.
Data types allow programming languages to provide different classifications for items of data, so they can be used for different purposes. The data type determines:
It is important to choose the correct data type for a given situation to ensure accuracy and efficiency in the program.
In pseudocode and some other programming languages, data types must be declared before they can be used. Each data item is given a unique name called an identifier.
Example: DECLARE Age : INTEGER
Primitive data types (also called atomic data types) refer to fundamental data types provided by a programming language. These data types are built into the language and are used to represent simple values.
| Data Type | Description | Examples |
|---|---|---|
| INTEGER | Whole numbers (positive or negative) | 10, -5, 0, 42, -100 |
| REAL | Numbers with fractional part (positive or negative) | 3.14, -2.5, 0.0, 99.99 |
| CHAR | A single character (letter, digit, or symbol) | 'a', 'B', '5', '$', '@' |
| STRING | A sequence of alphanumeric characters | "Hello World", "1234", "CS@9618" |
| BOOLEAN | Logical values - true or false only | TRUE, FALSE |
| DATE | Stores calendar dates | DD/MM/YY, "24/04/2025" |
Remember: CHAR uses single quotes ('A') while STRING uses double quotes ("Hello"). A string is known as a structured type because it is a sequence of characters. A special case is the empty string: a value of data type string, but with no characters stored in it (written as "").
Before data can be used, the data type needs to be decided. This is done by declaring the data type for each item to be used.
| Data Type | Pseudocode Example |
|---|---|
| INTEGER | DECLARE Age : INTEGER
Age ← 10 |
| REAL | DECLARE Temp : REAL
Temp ← 3.14 |
| CHAR | DECLARE Grade : CHAR
Grade ← 'A' |
| STRING | DECLARE Name : STRING
Name ← "Hello" |
| BOOLEAN | DECLARE LoggedIn : BOOLEAN
LoggedIn ← TRUE |
| DATE | DECLARE DOB : DATE
DOB ← "24/04/2025" |
When assigning values:
A record is a composite data type structure that contains a fixed number of components, which can be of different types. It allows programmers to collect together values with different data types under a single identifier.
A set of data related to one thing of different types is held under a single identifier. This makes code more organized and easier to maintain!
Records in programming are a type of data structure used to group related data in your code. These are not the same as records in a database, which refer to a complete set of fields on a single entity in a table (row)!
After defining the record type, you can declare a variable of that type:
Use the dot notation to access individual fields:
To output a field of a record:
The format is: RecordName.FieldName
We can use arrays of records to store multiple records of the same type. This is useful when we have several entities' data to work with and do not want to use a separate 1D array for each field.
Using the Person record type, we can declare an array for 100 person records:
We can access an individual's data using the array index combined with dot notation:
The format is: RecordArray[Index].FieldName
| Feature | Explanation |
|---|---|
| Can store different data types | Unlike arrays, records are not limited to a single type |
| Fields are named | Each item in the record has a meaningful identifier |
| Structured storage | Easier to manage complex data about real-world entities |
| Single identifier | All related data is grouped under one name |
| Fixed structure | The number and type of fields are defined once |
| Aspect | Array | Record |
|---|---|---|
| Data Types | Same type only | Different types allowed |
| Access Method | Index number | Field name |
| Size | Can be dynamic | Fixed number of fields |
| Use Case | Lists of same-type items | Related data of different types |
RECORD = Related Elements Collected Organized under Record Definition
Think of a record like a form you fill out - each field has a name and can hold different types of information!
When asked to define a record type, always include:
Answer:
Additional points for deeper understanding:
Answer:
Additional points for deeper understanding:
Answer:
Additional points for deeper understanding:
Answer:
Additional points for deeper understanding:
Answer:
Additional points for deeper understanding:
Answer:
Additional points for deeper understanding:
Answer:
Additional points for deeper understanding:
Answer:
Similarity:
Differences:
Answer:
Additional points for deeper understanding:
Answer:
Additional points for deeper understanding:
| Term | Definition |
|---|---|
| Data Type | A classification of data into groups according to the kind of data they represent |
| Primitive Data Type | Fundamental data types built into a programming language (e.g., INTEGER, REAL, CHAR, STRING, BOOLEAN, DATE) |
| Atomic Data Type | Another name for primitive data types - basic, indivisible data types |
| INTEGER | A data type for whole numbers, positive or negative (e.g., 42, -7, 0) |
| REAL | A data type for numbers with a fractional part (e.g., 3.14, -2.5) |
| CHAR | A data type for a single character, enclosed in single quotes (e.g., 'A', '5') |
| STRING | A structured data type for a sequence of characters, enclosed in double quotes (e.g., "Hello") |
| BOOLEAN | A data type that can only have two values: TRUE or FALSE |
| DATE | A data type for storing calendar dates (e.g., DD/MM/YYYY) |
| Identifier | A unique name given to a variable, constant, or other programming element |
| Record | A composite data structure containing a fixed number of fields of different data types |
| Field | A single item within a record, with its own name and data type |
| Composite Data Type | A data type composed of multiple primitive data types (e.g., records) |
| Dot Notation | The use of a dot (.) to access fields within a record (e.g., Person.Name) |
| Array of Records | An array where each element is a record of a defined type |
When asked to define a record, make sure you include:
Remember: TYPE starts it, ENDTYPE ends it, DECLARE for each field!
| ❌ Wrong | ✓ Right |
|---|---|
| Name ← "Ali" | DECLARE Name : STRING Name ← "Ali" |
| Grade ← A | Grade ← 'A' |
| Active ← "TRUE" | Active ← TRUE |
| Person[Name] ← "Ali" | Person.Name ← "Ali" |
| Topic | Key Point |
|---|---|
| Data Types | Determine what values can be stored and what operations are allowed |
| CHAR vs STRING | CHAR = single character ('A'), STRING = sequence ("Hello") |
| Record Access | RecordName.FieldName for single record, ArrayName[Index].FieldName for arrays |
| Record Advantage | Groups related data of different types under one identifier |