Seneca

Variables & Constants

Computer Science: KS3, topic 2.1.1

Variables and Constants

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

The memory

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.
  • The memory address looks something like 0x9FFF000F.
Variables

Variables

  • To make life easier for programmers, we can give a memory location a symbolic name.
  • The symbolic name is called an identifier.
  • The identifier is a word that describes what we will store in that memory location.
  • A variable is a named storage location.
  • The value of a variable can be changed while the program is running.
Constants

Constants

  • A constant is a named location in memory.
  • A constant can be used to store a value.
  • The value does not change while the program is run.
Assignment

Assignment

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

Test yourself on Variables & Constants

  • Which symbol is commonly used for assignment?

  • What is an identifier?

  • Why do programmers use an identifier instead of a memory address in their code?

  • Select the correct statement.

Practise this topic for free