Not a premium member yet? Save 100's of hours on lesson prep with a comprehensive library of GCSE Computer Science resources - including worksheets, tests, and PowerPoint presentations.
Download the complete GCSE Computer Science bundle including all teacher resources and student revision:
- 200+ Computer Science/ICT resources
+ any we release in the future!
- Access to all student revision notes
- OCR, AQA, Edexcel and WJEC compatible
- New 9-1 GCSE spec
Save 5+ hours a week on GCSE Computer Science lesson planning
Our teaching resources can be used to save many hours of lesson planning and preparation, as well as teaching your students the theory and practical skills they need to pass their GCSE Computer Science exams. For students the revision notes can be used to improve overall knowledge and have the best preparation possible for your examinations.View the Lessons →
Candidates should be able to:
- define the terms variable and constant as used in an imperative language
- use variables and constants
- describe the data types integer, real, Boolean, character and string
- select and justify appropriate data types for a given program
- perform common operations on numeric and Boolean data
- use one-dimensional arrays.
What are constants and variables?
Constants are symbolic names given to data where the value of the data cannot change during the execution of the program. Many constants such as PI are built into programming languages.
Variables are symbolic names given to data where the value of the data stored may change during the execution of the program. In effect, a variable is a named area of memory used to store data.
Declaring constants and variables
Many programming languages require constants and variables to be ‘declared’ at the start of the program, this defines the variable type (text, integer etc.) and sets the value of any constants.
- The value of a constant is set when it is declared and cannot change when the program is executed.
- A variable has no value when it is declared but it’s value can change when the program is executed.
Naming constants and variables
The name used to label a variable or a constant can be a single letter but many programming languages allow meaningful names to be used which make a program far easier to understand. In almost all languages, variable names cannot start with a digit (0–9) and cannot contain whitespace characters.
An example of a statement using constants and variables:
- The value of PI would be very tedious to have to keep entering in a program if it was used repeatedly in calculations. If a named constant is used to store the value of PI then this can be used instead.
CONSTANT PI = 3.142 INPUT circle_radius circle_area = PI * circle_radius * circle_radius
- Here the constant PI is used in a statement that calculates the area of a circle. The variable circle_radius is used to store the radius of the circle and the variable circle_area is used to store the result of the calculation.
What data types are used in programming?
Most programming languages require the user to declare the type of data stored in the variable or constant. Some of the most common examples are described below:
A character is a single letter, number or symbol and is treated a text, even if it is a number.
A string is made up of two or more characters.
name = “James” PRINT name + name
The output would be JamesJames
number = “7” PRINT number + number
The output would be 77
This data type is used to store real numbers i.e. values which might have decimal places.
number = 7.42 PRINT number + number
The output would be: 14.84
This data type is used to store whole numbers. i.e. values with no decimal places.
number = 7 PRINT number + number
The output would be: 14
This data type is used to store the logical data TRUE/FALSE
open = TRUE PRINT open
The output would be: TRUE
What is an array?
An array is a variable that can be indexed. The variables in the array have a common name and each one has an index to identify it within the array. As with normal variables, arrays can be text, real number, integer etc. The index is typically an integer number or integer variable.
The example below uses a text array named colour to store a series of named colours. The numbers 1-5 are the array index:
colour = “Red” colour = “Blue” colour = “Green” colour = “Orange” colour = “Yellow”
FOR count = 5 TO 1 STEP -1 OUTPUT colour[count] ENDFOR
Would produce the following output:
The advantage of using a numerical index in an array is that if the index is a variable it is easy to input and output data using an iteration loop as in the use of the variable count in the example above.
Some programming languages also allow the use of a text index as in the examples below:
contact[name] = "James" contact[age] = "27" contact[phone] = "07654852816"
The following statement would produce the output 27