Programming Basics (AQA A-Level Computer Science): Revision Notes
Programming Basics
Introduction to programming
Programming is the process of creating instructions for computers to follow. At its most fundamental level, a computer program is a collection of instructions that a computer works through in a logical sequence to complete a specific task. These instructions, along with the data they work with, are stored in the computer's memory—the location where both instructions and data reside while a program is running.
When programmers create software (also known as applications or apps), they write lines of code that tell the computer exactly what to do. This code is organised into an algorithm, which is a sequence of steps that can be followed to complete a task and that always terminates (comes to an end). Think of an algorithm as a recipe: it has a clear beginning, specific steps to follow in order, and a definite end point.
Just as a recipe tells you exactly how to make a cake step-by-step, an algorithm provides a computer with precise, ordered instructions to complete a task. The key difference is that algorithms must always reach an end point—they can't continue forever!
Just as there are many different human languages you can learn to speak, there are numerous programming languages available. Each programming language has many different versions and dialects, similar to how English is spoken differently in various parts of the world. What makes programming languages different from natural languages is that they have much stricter rules and a more limited vocabulary. These rules that define how words and symbols must be put together are called the syntax of the language. While natural languages are flexible and forgiving of mistakes, programming language syntax is rigid—the computer needs precise instructions to function correctly.
Naming and storing data
When a computer program runs, it needs both instructions and data to work with. For example, if you're writing a program to add two numbers together, you need the add instruction, but you also need the two numbers themselves. To make this work, you must give each piece of data a name so the computer knows which data to use and when.
Think of computer memory as a series of pigeon-holes, each with its own unique address. This is called a memory address—a specific location in memory where instructions or data are stored. When you create a variable in your program, the computer allocates a memory address to store that variable's value.
Why Meaningful Names Matter
Using meaningful names for your variables is crucial for three important reasons:
- It makes finding and correcting errors (a process called debugging) much easier
- When multiple programmers work on the same project, clear naming helps everyone understand the code
- When you need to update your program later, meaningful names help you remember what each variable does
While you could call your variables Number1 and Number2, using names that describe their purpose—like NumberOfMiles or UserAge—makes your code much easier to understand and maintain.
Most programmers follow a common naming convention where the first character is uppercase and the rest are lowercase (like StudentName or TotalCost). This isn't required by the computer, but it's good practice that makes code more readable.
The process of giving a value to a variable is called assignment. It typically looks something like this:
Number1 ← 23
Name ← "Derek"
The ← symbol means "becomes" or "equals". In this example, Number1 is a variable that has been assigned the value 23, and Name is a variable that has been given the value "Derek". Different programming languages use slightly different symbols for assignment (some use =, others use :=), but the concept remains the same.
Worked Example: Adding Two Numbers
Here's a simple algorithm that adds two numbers together:
Number1 = 2
Number2 = 3
Answer = Number1 + Number2
This program stores three pieces of data in memory. Each variable is stored at a different memory address as shown in the table below.

In reality, computer memory contains millions of addresses, but this simplified view shows the core concept: each variable has its own location in memory where its value is stored.
Constants and variables
Data in your program can be stored as either constants or variables, and understanding the difference is crucial.
A constant is an item of data whose value does not change throughout the program's execution. For example, if you're writing a program to convert miles to kilometres, you know that the conversion rate is approximately 1.6 kilometres per mile. This value never changes, so you would store it as a constant called something like ConvertMilesToKm with a value of 1.6. Then, whenever your program needs to convert a distance from miles to kilometres, it multiplies by this constant.
A variable is an item of data whose value could change while the program is running. Using the same conversion example, the number of miles that the user wants to convert will be different each time they use the program. Therefore, you need a variable (perhaps called NumberOfMiles) to store this changing value.
When to Use Constants vs Variables
Use a constant when:
- The value never changes during program execution
- You have fixed values like conversion rates, tax rates, or mathematical constants (like π)
- You want to prevent accidental changes to important values
Use a variable when:
- The value needs to change during program execution
- You're storing user input
- You're storing calculated results that vary
- You're tracking changing states (like scores, counts, or current positions)
Other examples of variables include:
- The number of correct answers a student has achieved in a test (this increases as they answer more questions correctly)
- A user's password (which can be changed at any time)
- The current score in a game
Variable and constant declaration
Declaration is the process of defining variables and constants in terms of their name and data type before you use them in your program. Some programming languages require you to declare all your variables and constants at the beginning of your program, before writing any other code. This has several benefits:
- It forces you to plan your program structure before you start coding
- The computer can quickly identify if you try to use a variable that doesn't exist
- It makes your code more organised and easier to read
When you declare a variable or constant, you need to provide two pieces of information: a suitable name and the data type.
Worked Example: Declaring Variables
Here are some examples of variable declarations:
Dimension Age As Integer
Dimension Name As String
Dimension WearsGlasses As Boolean
In these examples, Dimension (or Dim) is a command word used in Visual Basic to indicate that you're declaring a variable. Once declared:
Agestarts with a default value of zeroNamestarts as nothing (an empty string)WearsGlassesstarts as False
While variables have default values, it's good practice to assign an initial value explicitly to ensure your program works correctly.
Data types
When you write a program, you need to tell the computer what sort of data you're working with. This is where data types come in—they determine what sort of data are being stored and how the program will handle that data.
Think about the miles-to-kilometres conversion program again. You need to tell the program that both miles and kilometres are numbers so it can perform mathematical calculations. You also need to specify whether whole numbers are sufficient or if you need decimal places. Additionally, your program will likely store other types of data, such as the user's name (text) or their date of birth (a date).
Why Data Types Matter
Without proper data type declaration, the program might misinterpret your intentions. For example, if you don't specify that 2 and 3 are numbers, some languages might interpret 2 + 3 as "23" (joining two pieces of text together) rather than 5 (adding them mathematically).
All programming languages provide a range of built-in data types, though the exact names may vary between languages. Here are the most common ones:
Integer
An integer is any whole positive or negative number, including zero. This data type is used when you only need whole numbers, such as:
- The number of cars sold in a month
- The number of students in a class
- A person's age in years
The range of numbers that can be stored depends on how much memory is allocated. For example, an integer in Visual Basic can store numbers from –2,147,483,648 to +2,147,483,647.
When you declare a number as an integer, the program handles the data accordingly. For instance, 2 + 3 equals 5. However, if you didn't specify the data type properly, some languages might interpret 2 + 3 as "23" (joining two pieces of text together rather than adding them mathematically).
Real/Float
Real numbers (also called floating-point numbers) have a fractional or decimal part. You would use this data type for values like 3.5 or 3.14159. In the miles-to-kilometres conversion program, you'd need to use real numbers because the user might want to convert a value like 7.5 miles, and the answer won't necessarily be a whole number.
Other examples where you'd use real numbers include:
- A person's height in metres (e.g., 1.75m)
- A person's weight in kilograms (e.g., 68.4kg)
- The price of an item (e.g., £19.99)
Text/String
The text or string data type is used to store characters—this could be actual text or even numbers that you don't need to perform calculations on. Some programming languages call this "alphanumeric" because you can store any character you want in a string variable.
Examples include:
- A person's name (like "Frank")
- A person's address
- A phone number
Text or string variables are typically shown in quotation marks in code. For example, you might assign a name like this: Name ← "Frank".
When Numbers Aren't Really Numbers
House numbers and phone numbers are often stored as strings rather than integers. While they contain digits, you would never need to do mathematical calculations with them, and for phone numbers, the leading zero is important and would be lost if stored as a number.
Boolean
A Boolean is the simplest data type—it can only store two possible values: yes/no or true/false. It's named after George Boole, who discovered the principles behind logic statements.
Boolean data types are useful for storing any information that has exactly two possible states:
- Whether a person wears glasses (yes or no)
- Whether a student has completed their homework (true or false)
- Whether a user is logged in (true or false)
Character
The character data type stores a single individual character, which could be a letter, number, or symbol. All computers use a defined character set—a standard range of characters that the computer understands. This commonly includes all uppercase and lowercase letters, digits, keyboard symbols, and special characters.
While similar to strings, the character type is specifically for single characters rather than sequences of them.
Date/Time
This data type stores dates and times in a format that the computer can easily recognise and manipulate, such as 30.04.2014 or 12:30. The advantage of using a proper date/time data type is that the program can perform date-related operations correctly.
Worked Example: Date Arithmetic
If you declare a date variable and add 5 to it, the program knows you mean "five days later":
30.05.2014 + 5becomes04.06.2014(correct!)- If you didn't declare it as a date and just treated it as a regular number, you might get
30.05.2019(incorrect!)
The date/time data type ensures the computer handles dates intelligently, accounting for different month lengths and year boundaries.
Pointer/Reference
Think of computer memory as a series of addresses where data is stored. A pointer is a data item that identifies a particular element in a data structure—typically the front or rear of a collection. Rather than storing the actual data value, a pointer stores the memory address where the data can be found.
For example, you could create a pointer called Pointer1 and store the address 1001 in it. The program would then go to memory address 1001 and retrieve whatever data is stored there.

In this diagram, Pointer1 contains the value 1001, which directs the program to memory address 1001 where it finds Number2 with the value 3. The program can then use this value in subsequent operations.
Array
An array is a collection of data items of the same type, all stored under a single identifier. Imagine you want to store a list of student names in a school register—rather than creating separate variables like Student1, Student2, Student3, etc., you can create one array called Register that holds all the names.
Each individual item in an array is called an element, and each element is numbered so you can access specific items. For example:
Register(2)would give you the second person in the arrayRegister(4)would give you the fourth person
Array Indexing: Starting from 0 or 1?
It's important to note that many programming languages start counting from 0 rather than 1, so if the array uses zero-indexing:
Register(2)would actually be the third personRegister(4)would actually be the fifth person
Always check which indexing system your programming language uses!
Here's an example of a simple array with six student names:
| Brown | | Hussain | | Koening | | Schmidt | | Torvill | | West |
If this array is called Register and uses indexing starting at 1, then Register(2) = Hussain and Register(4) = Schmidt.
Arrays can also work in multiple dimensions (like a table or grid), which is useful for storing more complex structured data.
Record
A record is used to store a collection of related data items where the items have different data types. While arrays require all elements to be the same type, records allow you to mix different types.
Worked Example: Creating a Record Structure
You might create a record called Book to store information about books in a library:
Book = Record
Title, Author As Text * 50
ISBN As Text * 13
PublicationDate As Date
This record has four fields:
TitleandAuthor(both text, maximum 50 characters)ISBN(text, maximum 13 characters)PublicationDate(a date)
When the program runs, every time a user enters information about a book, all four pieces of data are stored together in one record variable, making the data easier to manage.
Built-in and user-defined data types
Built-in data types are those provided by the programming language itself. Every programming language includes standard data types like integers, strings, booleans, and so on, though the exact names and variations differ between languages.
Most programming languages also allow you to create your own user-defined data types by combining existing types together. This is useful for creating more efficient, organised code.
Worked Example: Creating a User-Defined Type
Imagine you're creating a program to store usernames and user IDs. You could create a custom data type called Logon:
Type Logon
UserName As String * 10
UserID As Integer * 5
End Type
This creates a new data type called Logon that consists of a 10-character username and a 5-digit user ID. In total, the data type uses 15 characters/digits to store the data.
Benefits of User-Defined Data Types
Why would you create user-defined types? There are several good reasons:
-
Efficiency: As you write more complex programs, they can become very long and time-consuming to debug. Creating reusable data types saves time as your program develops.
-
Code reuse: It's easier to reuse a block of code (like a data type definition) than to write it out repeatedly throughout your program.
-
Elegance and organisation: Professional programmers aim to create "elegant" code that does exactly what it's supposed to do as efficiently as possible, often with as few lines as possible and no repeated code.
-
Simplified access: With the
Logonexample above, all the user's login data is stored together in one variable rather than two separate ones. When the program needs this information, it only needs to access one variable instead of two, which is more efficient.
Remember!
Key Points to Remember:
- Programs are sequences of instructions stored in memory that tell computers what to do, organised as algorithms that always terminate
- Data is stored at memory addresses and should be given meaningful names following consistent naming conventions
- Constants have fixed values that don't change during program execution, while variables can change their values
- Declaration means defining variables and constants with names and data types before using them
- The main built-in data types are: integer (whole numbers), real (decimal numbers), string (text), boolean (true/false), character (single symbol), date/time, pointer (memory addresses), array (collections of same-type data), and record (collections of different-type data)
- User-defined data types are created by combining built-in types and make programs more efficient and easier to maintain