logo

Study resource

Programming revision notes

Study Programming with curriculum-aligned Revision Notes resources, practice links, and exam-focused support.

At a glance

revision notes

Resource type

Topic

Programming

AqaA LevelComputer ScienceFundamentals of programming

Revision notes

  • A-level Programming: Data, Control Structures and Subroutines

    Data types and declarations

    A data type describes the kind of value that can be stored and the operations that can be applied to it. Required types include integer, real/float, Boolean, character, string, date/time, pointer/reference, records and arrays. A variable can change during program execution, whereas a constant is given a value that is not intended to change. Named constants make programs easier to understand because a meaningful name can represent a fixed value.

    A pointer or reference stores a memory address referring to an object created dynamically at runtime. A record groups related fields, potentially of different types, and an array stores a collection of values of an appropriate type. A user-defined data type is based on language-defined built-in types. Identifiers should describe their purpose; meaningful names make assignments, conditions and subroutines easier to understand.

    Operations

    Arithmetic operations include addition, subtraction, multiplication, real division, integer division, remainders, exponentiation, rounding and truncation. Integer division produces an integer result and a remainder operation gives the amount left over. Rounding and truncation are different: rounding chooses a nearby value according to a rounding rule, while truncation removes part of a value without rounding it.

    Relational operations compare values: equal to, not equal to, less than, greater than, less than or equal to, and greater than or equal to. Boolean operations combine or change Boolean values: NOT reverses a Boolean value, AND requires both operands to be true, OR allows either operand to be true, and XOR is true when the Boolean operands differ.

    String operations include finding length and position, extracting a substring, concatenation, character-to-character-code conversion, character-code-to-character conversion and conversions between strings and integers, floats and date/time values. Conversion should be distinguished from concatenation: conversion changes the representation or type of a value, while concatenation joins strings. Random number generation can be used when a program needs a value selected randomly.

    Combining statements

    Imperative programs combine sequence, selection and iteration. Sequence executes statements in order. Selection chooses between alternatives, including nested selections. Iteration repeats statements. Definite iteration repeats a known number of times. Indefinite iteration continues until a condition changes, with the condition tested at the start or at the end of the structure. A start-tested loop may execute zero times; an end-tested loop has its condition after the body, so the body is executed before the test. Nested iteration places one iterative structure inside another.

    Selection and iteration depend on relational and Boolean expressions. For example:

    python if score >= pass_mark: result = "pass" else: result = "not pass"

    A common error is confusing assignment with comparison. Assignment gives a variable a value; a relational operation tests a relationship between values.

    Subroutines, scope and recursion

    A subroutine is a named, out-of-line block of code that can be called by writing its name in a program statement. Procedures perform an operation, while a function can return a value to the calling routine. Parameters pass data through a subroutine interface. Subroutines support decomposition and avoid repeating the same block of code, while meaningful interfaces make calls clearer.

    A local variable is declared inside a subroutine, exists only while that subroutine is executing and is accessible only within it. A global variable is available outside the individual subroutine. Local variables are good practice because their use is restricted to the subroutine that needs them, reducing unwanted dependence on variables elsewhere in the program.

    When a subroutine is called, a stack frame is used to store the return address, parameters and local variables. The return address identifies where execution continues after the subroutine finishes. Recursive subroutines call themselves. A correct recursive solution has a base case that stops further calls and a general case that makes progress towards the base case. Omitting or failing to reach the base case can prevent the recursion from terminating.

    Exception handling

    Exception handling deals with exceptional situations during program execution. The handling mechanism should be used with a programming language familiar to the student so that an appropriate response can be made when an exception occurs. It should not be confused with ordinary selection: selection chooses based on a Boolean condition, whereas exception handling addresses an exception raised during execution.

Related topics

Study nearby topics next