Data types and structures — Edexcel GCSE Computer Science
Data types and structures explained
Data types and structures covers 3 specification points, including Be able to write programs that make… and Be able to write programs that make….
Read the full explanation
Open a point below for its explanation and revision guidance.
6.3.1 be able to write programs that make appropriate use of primitive data types (integer, real, Boolean, char) and one- and two-dimensional structured data types (string, array, record)
This criterion requires you to choose and use data types correctly when writing programs. Primitive types hold single values: integer for whole numbers such as a score of 42, real for numbers with a fractional part such as a price of 3.75, Boolean for true or false such as a flag showing whether a user is logged in, and char for a single character such as the letter A. Structured types hold several values. A string is a sequence of characters, for example a name, and individual characters can be reached by index. A one-dimensional array stores many items of the same type under one name, such as ten test scores, accessed by a single index. A two-dimensional array stores items in rows and columns, such as a seating grid, accessed by two indices. A record groups related fields of possibly different types under one name, such as a student record holding a name, an age and a pass flag.
6.3.2 be able to write programs that make appropriate use of variables and constants
This criterion asks you to write working programs in which values that change are held in variables and values that must not change are held in constants. In an exam answer you would show a short program, for example a till that stores a price in a variable, updates it when a discount is applied, and keeps the VAT rate in a constant. Choose meaningful names, assign an initial value before first use, and update a variable by reassigning it. Declare a constant once with a fixed value and never reassign it. Use each appropriately: counters, totals and inputs are variables; fixed rates, maximum sizes and conversion factors are constants. Explain briefly why each choice suits the data.
6.3.3 be able to write programs that manipulate strings (length, position, substrings, case conversion)
This criterion asks you to write programs that process text. You need to find the length of a string, locate the position of a character or substring, extract part of a string, and change between upper and lower case. For example, given the string "Computer Science", length returns 16, position finds where a letter sits, a substring extracts characters between two indices, and case conversion produces "COMPUTER SCIENCE" or "computer science". Remember that positions are usually counted from zero, so the first character is at index 0. Combine the operations, such as taking a username, converting it to lower case and extracting the first three letters.
Your focus
- Declare and use integer, real, Boolean and char variables appropriately in a program.
- Store and retrieve data using strings, one-dimensional arrays, two-dimensional arrays and records.
- Justify the choice of data type or structure for a given set of data.
Show all 9 objectives
- Write a short program that declares and uses at least one variable and one constant.
- Update a variable correctly through reassignment and show the resulting value.
- Justify why a named value is stored as a variable or as a constant.
- Write code that finds the length of a string and the position of a character or substring.
- Extract a required substring using correct start and end positions.
- Convert a string to upper or lower case and combine string operations to solve a task.
Data types and structures exam tips
Marking Points
- Primitive types: integer is used for whole numbers, real for fractional values, Boolean for true or false, and char for a single character.
- String handling: a string stores a sequence of characters and individual characters or substrings are accessed correctly by index or slicing.
- One-dimensional array: many values of the same type are stored under one identifier and accessed by a single index, with correct bounds.
- Two-dimensional array: values are stored in rows and columns and accessed by two indices, for example grid[row][column].
- Record: related fields of different types are grouped under one name and each field is accessed by its field name.
- Type selection: the candidate justifies why a real rather than an integer is needed for a price, or why a Boolean suits a yes/no flag.
- Declaration and assignment: variables are declared with a suitable type and assigned values that match that type without conversion errors.
- Explanation: the candidate explains the difference between a primitive type holding one value and a structured type holding many.
- Declares or assigns at least one variable and gives it a meaningful name that reflects its purpose.
- Assigns an initial value to each variable before it is used in a calculation or output.
- Updates a variable by reassignment, for example adding to a running total or incrementing a counter.
- Declares at least one constant with a fixed value and does not reassign it anywhere in the program.
- Chooses variables for values that change during execution and constants for values that stay fixed.
- Uses the variable or constant correctly in an expression, condition or output statement.
- Justifies the choice of variable or constant for a named value in the program.
- Uses a length operation to return the number of characters in a string.
- Uses a position or index operation to find where a character or substring occurs.
- Extracts a substring using start and end positions or a start position and length.
- Converts a string to upper case or lower case as required by the task.
- Applies string operations in a sensible order to produce the required output.
- Handles indexing correctly, including counting from zero where the language uses zero-based indexing.
- Combines two or more string operations in one program to solve a stated problem.
Examiner Tips
- 💡For each variable you declare, write a one-line comment stating its type and purpose so your type choices are visible.
- 💡When using a two-dimensional array, state clearly whether the first index is the row and the second the column, and keep that order consistent.
- 💡Check every assignment against the declared type, especially where input is read as text and must be converted to an integer or real before use.
- 💡Write the program first, then add one or two sentences explaining why each value is a variable or a constant.
- 💡Keep names consistent between the code and your explanation so the examiner can follow your reasoning.
- 💡Test your logic with a simple trace: state the starting value, the change and the final value for each variable.
- 💡State the indexing convention you are using so your position values can be checked.
- 💡Work through a short example string character by character before writing the code.
- 💡Show the expected output for a sample input to demonstrate that your operations are correct.
Common Mistakes
- Storing a fractional value such as 3.75 in an integer variable, which truncates it to 3. Correction: declare the variable as a real so the fractional part is kept.
- Confusing a char with a string of length one and using string operations on a single character. Correction: use char for one character and string for a sequence, and convert only when the task requires it.
- Using a one-dimensional array for data that naturally has rows and columns, then losing track of which index means what. Correction: use a two-dimensional array and access it with two indices, row first then column.
- Treating a record as an array and trying to reach a field by number. Correction: access each field by its field name, since fields may have different types.
- Using a variable for a fixed value such as a VAT rate and then changing it; the correction is to store fixed values in a constant and leave them unchanged.
- Reading a variable before any value has been assigned, which gives an undefined or default value; the correction is to assign an initial value first.
- Giving names such as x or data that hide meaning; the correction is to use descriptive names such as totalCost or vatRate.
- Treating a constant as if it could be reassigned later in the program; the correction is to set it once and use it read-only.
- Assuming the first character is at position 1 when the language counts from zero; the correction is to check the indexing convention and adjust positions.
- Confusing the length of a string with the position of its last character; the correction is to remember that the last index is one less than the length in zero-based indexing.
- Extracting a substring with the end position included when the operation excludes it; the correction is to check whether the end index is exclusive and adjust by one.
- Forgetting that case conversion returns a new string rather than changing the original in place; the correction is to store or use the returned value.