2.1.1

Variables & Constants

Test yourself

Variables and Constants

We may need to store data in the memory as part of our program.

Illustrative background for The memoryIllustrative background for The memory ?? "content

The memory

  • The memory can be thought of as split up into 'blocks' called words.
  • Each word is usually 32 or 64 bits long.
  • To access a piece of memory, you have to use its memory address which looks something like 0x9FFF:000F.
Illustrative background for VariablesIllustrative background for Variables ?? "content

Variables

  • To make life easier for programmers, we can give a memory location a symbolic name called an identifier.
  • The identifier is a word which describes what we will store in that memory location.
  • A variable is any part of the memory that we have named, and that we can change the value of while the program is running.
Illustrative background for ConstantsIllustrative background for Constants ?? "content

Constants

  • A constant is a named location in memory that can be used to store a value which does not change while the program is run.
Illustrative background for AssignmentIllustrative background for Assignment ?? "content

Assignment

  • The process of setting a value to a variable or a constant is known as assignment.
  • Assignment is usually shown using an equals sign, e.g:
    • height = 39.

Jump to other topics

1Computational Thinking & Algorithms

2Programming

3Hardware & Software

4Data

5The Internet

6Online Safety & Security

Go student ad image

Unlock your full potential with GoStudent tutoring

  • Affordable 1:1 tutoring from the comfort of your home

  • Tutors are matched to your specific learning needs

  • 30+ school subjects covered

Book a free trial lesson