Homepage
Accessibility links
- Skip to content
- Accessibility Help
BBC Account
Notifications
- Home
- News
- Sport
- Weather
- iPlayer
- Sounds
- Bitesize
- CBeebies
- CBBC
- Food
- Home
- News
- Sport
- Reel
- Worklife
- Travel
- Future
- Culture
- TV
- Weather
- Sounds
More menu
Search Bitesize Search Bitesize
- Home
- News
- Sport
- Weather
- iPlayer
- Sounds
- Bitesize
- CBeebies
- CBBC
- Food
- Home
- News
- Sport
- Reel
- Worklife
- Travel
- Future
- Culture
- TV
- Weather
- Sounds
BITESIZE
- Home
- Learn
- Support
- Careers
- My Bitesize
GCSE
Eduqas
Data structures and data types
Variables, constants and arrays form the basis for how data is stored within a program. They must be declared with meaningful identifier names and appropriate data types that match the data. Without the correct data structures and data types, programs will not work.
Part of
Computer Science
Computational thinking and programming
quiz
Testprevious
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- Page4of 8
next
Variables and constants
Programs usually use data in some shape or form. Data in programs is usually referred to as values.
Variables
A variable is a named memory location that holds a value. The value held in a variable can - and usually does - change as the program is running.
Variables make it easy for a programmer to use memory locations. The computer keeps track of which memory location the variable refers to. All the programmer has to do is remember the name of the identifier the variable was given.
Declaration and assignment
Most programming languages require a variable to be identified before a value is assigned to it. This is known as declaring a variable:
score is integerThis would declare a variable called score that would hold integers.
Giving a variable a value is known as assignment. A variable must be assigned a value before it can be used. For example:
set score = 0This would assign the value 0 to the variable score.
Some programming languages, such as Python, enable variables to be declared and assigned a value in the same line of code.
Constants
A constant allows a value to be assigned an identifier name. Unlike a variable, the value assigned to a constant cannot be changed whilst the program is running.
Constants are useful because they are declared and assigned once, but can be referred to over and over again throughout the program. They are used for values that are unlikely to change, for example:
- pi, eg constant PI = 3.142
previous
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- Page4of 8
next
GCSE Subjects
- Art and Design
- Biology (Single Science)
- Business
- Chemistry (Single Science)
- Combined Science
- Computer Science
- Design and Technology
- Digital Technology (CCEA)
- Drama
- English Language
- English Literature
- French
- Geography
- German
- History
- Home Economics: Food and Nutrition (CCEA)
- Hospitality (CCEA)
- ICT
- Irish – Learners (CCEA)
- Journalism (CCEA)
- Learning for Life and Work (CCEA)
- Mandarin
- Maths
- Maths Numeracy (WJEC)
- Media Studies
- Modern Foreign Languages
- Moving Image Arts (CCEA)
- Music
- Physical Education
- Physics (Single Science)
- PSHE and Citizenship
- Religious Studies
- Science
- Sociology
- Spanish
- Welsh Second Language (WJEC)