Pearson Edexcel GCSE (9-1) · Computer Science (1CP2)

Subprograms: Practice Questions

5 multiple-choice questions marked as you go, and 5 written questions with worked solutions. All on Subprograms.

10 questions28 marksFree, no account
Question 1
1 mark

A programmer wants to break down a complex problem into smaller, manageable parts. What is a primary benefit of using subprograms for this purpose?

Question 2
1 mark

A function is defined as follows:
function calculate(a, b)
    return a * b + 2
endfunction

What is the output of print(calculate(3, 4))?

Question 3
1 mark

A subprogram is designed to update a user's score in a database but does not need to send any data back to the part of the program that called it. Which type of subprogram is this?

Question 4
1 mark

Which of the following describes the difference between a global variable and a local variable used within a subprogram?

Question 5
1 mark

Which of the following is a potential risk of using global variables instead of passing parameters to subprograms?

Question 6
3 marks

Explain why a programmer would use a function rather than a procedure when calculating the square root of a number.

Write your answer out first, then check it against the worked solution.

Question 7
5 marks

A variable total is declared inside a subprogram. Explain the effect on the program if you attempt to access total from the main program block.

Write your answer out first, then check it against the worked solution.

Question 8
6 marks

Describe two characteristics of a function that distinguish it from a procedure within the Pearson Edexcel PLS.

Write your answer out first, then check it against the worked solution.

Question 9
3 marks

A program uses a subprogram to calculate the total price of items including tax. The subprogram takes the price as an input and returns the final value.

(a) Explain one benefit of using subprograms in this scenario.
(b) Define the difference between a parameter and an argument in the context of this subprogram.

Write your answer out first, then check it against the worked solution.

Question 10
6 marks

Consider the following subprogram snippet:
FUNCTION calculate(a, b)
  global total
  total = a + b
  RETURN total * 2
ENDFUNCTION


(a) Distinguish between the local variables and global variables in this snippet.
(b) Explain one potential risk of using the global keyword inside a subprogram.
(c) Rewrite the subprogram so it does not use a global variable but still allows the calling program to use the sum.

Write your answer out first, then check it against the worked solution.

* The content provided by thinka is generated by AI and may not always be accurate or up-to-date. Please use it as a supplementary resource and verify with official materials.

You've seen the model answer. Now get yours marked.

This page can show you how a good answer looks. It cannot tell you what your answer was missing. thinka marks your written work against the real mark scheme in about 15 seconds.

Want more questions like these? Get a fresh set on this topic, graded as you go.

Practice More