Variables & Constants (CIE IGCSE Computer Science)

Revision Note

Test Yourself
Becci Peters

Expertise

Computer Science

Variables & Constants

Variables and constants are used to store a single item of data in a program. This can be accessed through the identifier. Variables can be changed during program execution while constants remain the same.

Declaring Variables and Constants

  • Variables are declared using a data type, a name and a value (optional)
  • Constants are declared using the 'const' keyword, a name and a value
  • In all programming languages, variable names should follow certain rules, such as:
    • Starting with a letter
    • Not containing spaces
    • Can contain letters, numbers, _ or $
    • Not using reserved words (like if, while, for etc.)
  • Examples of data types include integer, float, boolean, and string

Examples in Pseudocode:

Declare a variable called 'score' with a value of 10

score 10

Declare a constant called 'PI' with a value of 3.14

const PI 3.14

Examples in Python:

Declare a variable called 'score' with a value of 10

score = 10

Declare a constant called 'PI' with a value of 3.14

PI = 3.14

Examples in Java:

Declare a variable called 'score' with a value of 10

int score = 10;

Declare a constant called 'PI' with a value of 3.14

final double PI = 3.14;

Examples in Visual Basic:

Declare a variable called 'score' with a value of 10

Dim score As Integer = 10

Declare a constant called 'PI' with a value of 3.14

Const PI As Double = 3.14

Exam Tip

  • Exam questions will ask you to write pseudocode statements, rather than in a specific language

Worked example

The variables 'name' and 'age' are used to store data in a program:

  • name stores the user’s name
  • age stores the user’s age

Write pseudocode statements to declare the variables name and age.

[2] 

DECLARE name : STRING [1]
DECLARE age : INTEGER [1]

You've read 0 of your 0 free revision notes

Get unlimited access

to absolutely everything:

  • Downloadable PDFs
  • Unlimited Revision Notes
  • Topic Questions
  • Past Papers
  • Model Answers
  • Videos (Maths and Science)

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

Becci Peters

Author: Becci Peters

Becci has been a passionate Computing teacher for over 9 years, teaching Computing across the UK helping to engage, interest and develop confidence in the subject at all levels. Working as a Head of Department and then as an educational consultant, Becci has advised schools in England, where her role was to support and coach teachers to improve Computing teaching for all. Becci is also a senior examiner for multiple exam boards covering GCSE & A-level. She has worked as a lecturer at a university, lecturing trainee teachers for Computing.