teach-ict.com logo

THE education site for computer science and ICT

3. Assigning variables

The simplest type of variable is a single value, for example:

single valued variable

The line of pseudocode above is setting the value of the variable called 'z' to '10'. This value is then stored in the computer's memory.

One of the handy things about giving a name to a variable is that you do not need to care where in memory 'z' is located - the operating system is taking care of all that.

If you want to use 'z' again bit later in the code, then you use its name. Like on line 12 here:


    Line 10:      z ??? 10                                // assign 10 to z
    Line 11:      another_variable ??? 1                  // assign 1 to another_variable
    Line 12:      new_variable ??? z + another_variable   // do a calculation and store in new_variable  

Variables can get more complex than this. For example a variable might be a list of values (called an array):

list or array variable

This is discussed further in a section covering arrays.

Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: Assigning variables