Assignment, scope and declaration


In order to change the data value stored in a variable, you use an operation called assignment. This causes the value to be copied into a memory location, overwriting what was in there before.

Different values may be assigned to a variable at different times during the execution of a program. Each assignment overwrites the current value with a new one.


The scope of variables can be local or global.

  • local variables only work in the loop, procedure or class they are created in
  • global variables can be accessed from any point in a program


Declaring a name for a variable is saying what the data type will be and where it will be stored in memory.

Information about named constants and variables being used in a program is given in the form of declarations. These are sections of program code that define the names that will be used to refer to variables, and what kind of data each of them will hold.

Move on to Test