Pearson Edexcel IGCSE · Computer Science

Constructs: Practice Questions

2 multiple-choice questions marked as you go, and 4 written questions with worked solutions. All on Constructs.

6 questions20 marksFree, no account
Question 1
1 mark

Study the following pseudocode which involves variable scope:

\( \text{SET globalVar TO 10} \)
\( \text{FUNCTION calculate(n)} \)
  \( \text{SET localVar TO n * 2} \)
  \( \text{SET globalVar TO globalVar + 5} \)
  \( \text{RETURN localVar} \)
\( \text{ENDFUNCTION} \)

If the main program calls \( \text{calculate(4)} \) once, what will be the final value of globalVar and the returned result?

Question 2
1 mark

Consider the following pseudocode fragment:

\( \text{SET count TO 0} \)
\( \text{FOR r FROM 0 TO 2} \)
  \( \text{FOR c FROM 0 TO 1} \)
    \( \text{IF vals[r][c] > 10 THEN} \)
      \( \text{SET count TO count + 1} \)
    \( \text{END IF} \)
  \( \text{END FOR} \)
\( \text{END FOR} \)

The 2D array \( \text{vals} \) contains the following data:
Row 0: 12, 5
Row 1: 8, 15
Row 2: 20, 7

What will be the final value of the variable \( \text{count} \) after execution?

Question 3
3 marks

Explain the primary difference between a count-controlled iteration and a condition-controlled iteration.

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

Question 4
5 marks

An algorithm uses a nested loop to calculate the sum of values in a 2D array. If the inner loop is defined as \( \text{FOR j FROM 0 TO 5} \) but the array rows only contain 4 elements (indices 0 to 3), identify the type of error that occurs and explain its impact on the program execution.

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

Question 5
4 marks

Selection and iteration are fundamental programming constructs.
(a) Describe the difference between a count-controlled loop (FOR loop) and a condition-controlled loop (WHILE loop).
(b) Provide one specific programming scenario where a WHILE loop would be a more appropriate choice than a FOR loop.

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

Question 6
6 marks

A programmer is writing a subprogram to calculate the discount on a customer order.
(a) Explain the difference between passing by value and passing by reference when providing arguments to a subprogram.
(b) Discuss the benefits of using local variables within this subprogram instead of using global variables to track calculation steps, referring to data security and memory management.

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, marked as you go.

Practise More