2.2.1 Programming Techniques Exam Questions
Paper 2 · Algorithms & Programming · 7 past paper questions · 2 practice questions · 28 marks
Exam questions for 2.2.1 Programming techniques
7 OCR past paper questions and 2 practice questions (28 marks) with mark schemes
Answer each question, reveal the mark scheme, then award yourself marks. Scores and answers are saved in this browser so you can see which topics need more work.
Download Questions & Mark Scheme (PDF)Past paper questions
- Question 1H446/021 mark
Line 06 of a pseudocode program is: first = int(first). The variable first holds a value that the user has typed in. State the purpose of line 06.
Show mark scheme
Converts the string to an integer / casts to integer / type conversion from string to int (1 mark)Mark yourself: how many marks did you get?/ 1 - Question 2H446/024 marks
Describe one benefit and one drawback of using global variables instead of parameter passing in a subroutine.
Show mark scheme
Benefit: Can be accessed anywhere / No need to pass as parameter / Simpler function calls / Maintains state Drawback: Can be changed unintentionally / Harder to debug / Creates dependencies / Reduces modularity / Not thread-safe (4 marks - 2 per point)Mark yourself: how many marks did you get?/ 4 - Question 3H446/02 · June 20242 marks
Describe what is meant by a variable.
Show mark scheme
A named location in memory / Stores a value that can change during program execution / Has an identifier and a value / Can be read from and written to (2 marks)Mark yourself: how many marks did you get?/ 2 - Question 4H446/02 · June 20241 mark
A student has written this pseudocode algorithm. Give the identifiers of all the variables used in this program.
01 a = 12 02 do 03 b = input("Enter a number") 04 until b >= 0 and b <= 100 05 for c = 1 to a 06 print(c * a) 07 next cShow mark scheme
a, b, c (1 mark - all three needed)Mark yourself: how many marks did you get?/ 1 - Question 5H446/02 · June 20242 marks
Describe the difference between a do loop and a while loop.
Show mark scheme
Do loop: executes at least once, condition checked at end / While loop: condition checked at start, may not execute at all / Do loop is post-condition, while is pre-condition (2 marks)Mark yourself: how many marks did you get?/ 2 - Question 6H446/029 marks
Compare the use of variables and parameters in a treasure-hunting game. Include: local and global variables, how they can be used, passing parameters by value and by reference.
Show mark scheme
Levels of response (9 marks) Local: exists only within subroutine, destroyed when subroutine ends Global: accessible throughout program, persists for program lifetime Use: Board could be global (accessed everywhere), score local to display function By value: copy made, original unchanged, safe for read-only By reference: pointer to original, changes affect original, needed for updatesMark yourself: how many marks did you get?/ 9 - Question 7H446/022 marks
A function isInteger(number) takes a string and checks that every character is a digit by comparing ASCII values inside a loop that uses count as the index. Write the condition, using asc(), that is true when the character number[count] is not a digit from 0 to 9.
Show mark scheme
if asc(number[count]) < 48 OR asc(number[count]) > 57 then or equivalent checking ASCII values 48-57 (2 marks)Mark yourself: how many marks did you get?/ 2 - Question 8Practice question · H446/02 style4 marks
Write a recursive function factorial(n) that returns n! for a positive integer n, and identify the base case.
Show mark scheme
• function factorial(n) header with correct parameter • Base case: if n == 1 (or n == 0) then return 1 • Recursive call: return n * factorial(n - 1) • Correct structure / endfunction, with the base case reached before the recursive case Example: function factorial(n) if n <= 1 then return 1 else return n * factorial(n - 1) endif endfunction (4 marks – 1 per point)Mark yourself: how many marks did you get?/ 4 - Question 9Practice question · H446/02 style3 marks
Explain the difference between passing a parameter by value and passing it by reference. Give one situation in which passing by reference is preferable.
Show mark scheme
• By value: a copy of the data is passed, so changes made inside the subroutine do not affect the original variable • By reference: the address of the variable is passed, so changes inside the subroutine change the original variable • Preferable when a large data structure would be slow or memory-hungry to copy, or when the subroutine must update the caller's variable (e.g. a procedure that sorts an array in place) (3 marks – 1 per point)Mark yourself: how many marks did you get?/ 3
- 1Recursion: Must have base case; Stack behaviour; Compare to iteration
- 2Variable scope: Local (subroutine only) vs Global (entire program)
- 3Parameter passing: By value (copy) vs By reference (can modify original)
- 4OOP: Encapsulation, classes, objects, private vs public
- •Practice answering questions under timed conditions
- •Check your answers against the mark scheme carefully
- •Focus on understanding the marking points, not just memorising answers
- •Review past paper questions from multiple years to spot patterns