OCR GCSE Computer Science 2.2 Programming fundamentals: data types, the three constructs, operators, arrays, strings, files and subprograms
A deep-dive OCR GCSE Computer Science guide to topic 2.2 Programming fundamentals. Covers variables, constants and data types, sequence, selection and iteration, arithmetic, comparison and Boolean operators, arrays and records, SQL, string manipulation and file handling, and subprograms, with the OCR Exam Reference Language throughout.
Reviewed by: AI editorial process; not yet individually human-reviewed
Jump to a section
What topic 2.2 actually demands
Programming fundamentals is the toolkit for writing programs and is examined in Paper J277/02, including the practical Section B. It rewards being able to read and write the OCR Exam Reference Language fluently: declaring and choosing data types, using the three constructs, applying operators (especially MOD and DIV), and using arrays, strings, files and subprograms. Practise writing code, not just reading it.
This guide ties together the six dot-point pages for the topic.
Variables, constants and data types
A variable can change as the program runs; a constant is fixed once set. The common data types are integer (whole numbers), real/float (decimals), Boolean (true/false), character (one symbol) and string (text). Choose the type that fits the data, and cast with int(...), real(...), str(...) and bool(...) to convert, for example turning user input (a string) into a number.
Sequence, selection and iteration
Programs are built from three constructs. Sequence runs statements in order. Selection branches on a condition (if ... then ... elseif ... else ... endif, or switch/case). Iteration repeats: a count-controlled for loop for a known number of repetitions, and condition-controlled while (checks before, may run zero times) and do ... until (checks after, runs at least once) loops for an unknown number.
Operators
Arithmetic: +, -, *, /, exponent, and crucially DIV (integer division, the quotient) and MOD (the remainder). Comparison: ==, !=, <, >, <=, >=, which give a Boolean. Boolean: AND (both true), OR (at least one true), NOT (reverses). MOD and DIV are the most heavily examined.
Arrays, records and SQL
An array stores many values of one type under a name, accessed by a 0-based index; a 2D array is a grid with row and column indexes. A record groups related fields of different types. SQL searches database records: SELECT fields FROM table WHERE condition.
Strings, files and subprograms
String operations include .length, .substring(start, length), concatenation with +, .upper/.lower, and ASC/CHR for character codes. File handling uses openRead/openWrite, .readLine(), .writeLine(), .endOfFile() and .close(). Subprograms are procedures (no return value) and functions (return a value), take parameters, and use local or global variables; they reduce repetition and aid decomposition, testing and maintenance.
Check your knowledge
A mix of recall and applied questions covering topic 2.2. Attempt them, then check against the solutions.
- Name the five common data types. (2 marks)
- State the difference between a variable and a constant. (1 mark)
- State the result of 19 DIV 4 and 19 MOD 4. (2 marks)
- Name the two kinds of iteration and when each is used. (2 marks)
- State the value of data[0] for data = [9, 8, 7]. (1 mark)
- Write an SQL query to return all fields from Members where Age is over 18. (2 marks)
- State the difference between a procedure and a function. (1 mark)
- State one benefit of using subprograms. (1 mark)
Sources & how we know this
- OCR GCSE (9-1) Computer Science (J277) specification — OCR (2020)