Digital development concepts

Computer programs use data stores to organise different data within a program.

Data can be constant or variable within programs and functions. When we create a program, we also need to create ways for users to input data into the program and output information from it.

Input, output, variables, constants and assignment

To store data within a computer program you need to create a data store. This can either be a constant, a variable or an array.

Variables

A variable is a named memory location. Data stored in that location changes throughout the duration of the program, for example the high score in a computer game.

When we create a variable, we allocate a space in the memory for it and give it a name.

We give variables names as identifiers to help explain the value assigned to it. For example, age = 16.

We assign values to variables using an assignment operator. For example, = (the 'equals' sign).

We can change the value of our variable at any time during the running of a program. For example, age = age + 1. Here, we have added 1 to the value of the variable 'age'. The age variable will now store the value 17.

Constants

A constant is a named location in memory that contains a value, that does not change during the execution of a program. Data is assigned to a constant in the same way as a variable. For example, in a computer game:

CONST CHARACTERSPEED = 5 CONST GRAVITY = -5

When writing code, we often use UPPER CASE to help identify constants.

Arrays

If you need to store multiple values you will need to use an array. This is a set of values of the same data type stored under one identifier.

Input functions

To get input from a user we have to use an input function. The input function is used to ask the user a question, and invites them to give a response. This value of this user response is then returned as the result of the function, and is stored in a variable. By default, this will be a string, however we can use casting (converting one data type into another) to change the data type. For example:

An example of an input function

To output information from a computer program we use a print procedure (this is not used for printing output on to paper). Most programming languages will provide a print procedure for writing or displaying information to the screen. For example:

An example of a print procedure