Lesson 4.1.1.10
4.1.1.10 Subroutines Quiz: AQA Computer Science, Unit 1
20 questions
In partnership with Revision Ninja
Lesson 4.1.1.10, Subroutines: 20 multiple choice questions for the AQA Computer Science (7517), Unit 1: Fundamentals of programming, written with Revision Ninja.
Host it live on the board and students join with a game code on their own devices, or revise alone with Free Play. The answers are revealed in the game.
The 20 questions
-
What is a subroutine?
- A data type built from records that groups several fields together under one shared name
- A named block of code that is called by writing its name
- A variable that stores a memory address pointing to a block of code held elsewhere in memory
- A loop that runs a fixed number of times, with its counter updated at the end of each pass
-
Which is an advantage of using subroutines in a program?
- The same code can be reused without being written out again
- Variables no longer need declaring
- The program always uses less memory than any alternative
- Errors are removed automatically
-
What is the difference between a procedure and a function, as commonly defined?
- A function returns a value to the caller, while a procedure does not return a value
- Procedures and functions are identical in all respects
- A function can only be called from within itself
- A procedure returns a value, while a function never returns anything
-
A program has a subroutine called printHeader that is used at the start of several outputs. Why is this a sensible design?
- It makes the header appear in every line of the program, so that every output line is formatted
- It forces the program to run more slowly, but the code is easier to read for other programmers
- It stops the program needing any variables, because the subroutine stores all the values it needs
- It avoids repeating the same code and so reduces errors when changing it
-
A subroutine is called from several places in a program. Where is the code of the subroutine stored?
- Once for each place it is called, so the code is copied to each place that uses the subroutine
- In the main program only, and the subroutine itself is kept in a separate file on disk each time
- In a constant named after the subroutine, so that the code cannot be changed during execution
- Once, in a single place, and each call transfers control to it
-
A program calls a subroutine from line 20 and the subroutine finishes. Where does control normally return?
- To line 1 of the subroutine
- To the start of the program
- To the end of the file where the program stops immediately
- To the statement after the call on line 20
-
Which statement best describes a subroutine's role in structured design?
- It is a named, self-contained task that can be reused and tested separately
- It is a loop that must run before the main program, setting up the values used by the main program
- It is a type of file on disk that holds the output of the program in a fixed binary layout
- It is a constant used to store results that the main program reads in at the end of the run
-
Why are subroutines sometimes described as out-of-line blocks of code?
- Because they are only used in printing
- Because they are always written at the end of the file and never run
- Because they are stored apart from the main sequence and entered only when called
- Because they cannot contain any statements
-
A subroutine named total is called 3 times in a program, and each call returns a value used in a sum. What does this show?
- The subroutine can only be called once, because a second call would overwrite its stored result
- Each call must use a different subroutine name, because a name can only be called once in a program
- The sum must be stored as a constant, since a variable would change each time the subroutine runs
- The same subroutine can be reused to produce several results
-
Which statement about the advantages of subroutines is most accurate?
- They remove the need for variables and loops everywhere, because all work is done by calls
- They make all data global by default, so every subroutine can read and write every value
- They help to decompose a problem, making it easier to design, read and test
- They guarantee that no errors will ever occur, so testing of each subroutine is not needed
-
A programmer writes a subroutine to calculate VAT and calls it in two different parts of a shop program. What is the main benefit?
- The VAT calculation runs twice as fast, because the subroutine is compiled separately from the program
- The calculation becomes a Boolean, so the program records only whether VAT applies to each sale
- The program no longer needs a VAT rate, since the subroutine works out the rate from the price
- The VAT calculation is defined once, so a change to the rate is made in one place
-
A subroutine is defined but never called in the main program. What is its effect?
- It causes the program to crash
- It changes every variable in the program
- It is never executed while the program runs
- It runs automatically at the start of the program
-
A program uses a subroutine to check a password, and the check is needed at both sign in and sign up. What is the best reason to write it as a subroutine?
- So that the password is stored in a constant, which means the value can never be changed later
- So that no selection is needed in the program, because the check replaces every IF statement
- So the check always returns TRUE, so that any password entered is accepted without an error
- So the same checking logic is used in both places without duplication
-
Which term describes a subroutine that is defined inside another subroutine or program and only used there?
- Nested subroutine
- Global constant
- Record field
- Pointer variable
-
A program needs to run a sequence of instructions for a menu option, then return to the menu. What is the most natural use of a subroutine?
- Store the instructions in a constant string, which the program then reads one character at a time
- Copy the instructions into every menu option, so that each option carries its own full sequence
- Use a Boolean to show the menu, so that the menu options are selected by a yes-or-no question
- Wrap the sequence in a named subroutine and call it from the menu
-
Which statement about naming a subroutine is most accurate?
- The name must be a single letter for speed, since the compiler looks up short names faster
- A good name describes what the subroutine does so its call reads clearly
- The name must always be the same as a variable, so that the call and the variable share memory
- The name has no effect on how the program is read, because the compiler ignores the identifier
-
A subroutine call appears inside a loop that runs 100 times. How many times is the subroutine executed?
- 100
- 10
- 0
- 1
-
Why are subroutines useful when a program is being tested?
- Each subroutine can be tested separately with known inputs and expected outputs
- They replace the need for any input data, so the test can be run without supplying values
- They prevent tests from being written at all, because subroutines cannot be checked separately
- They remove all bugs from the main program automatically, so the program needs no later testing
-
A program calls a subroutine that itself calls a second subroutine. What is needed so the program can resume correctly after the second subroutine finishes?
- All variables must be deleted
- The second subroutine must be a constant
- The program must restart from the beginning
- The return address for each call must be remembered
-
A subroutine is used to print a line of stars 20 characters long. Which is a sensible design choice for its length?
- Pass the length as a parameter so the subroutine can print any length
- Hardcode 20 and also store it as a global variable and a constant
- Change the length in every call by copying the code
- Make the length a Boolean
Related quizzes
- Data types Quiz · 4.1.1.1 · 20 questions
- Programming concepts: sequence, selection and iteration Quiz · 4.1.1.2 · 20 questions
- Arithmetic operations Quiz · 4.1.1.3 · 20 questions
- Relational and Boolean operations Quiz · 4.1.1.4 · 20 questions
- Constants and variables Quiz · 4.1.1.6 · 20 questions
- String-handling operations Quiz · 4.1.1.7 · 20 questions
- Random numbers and exception handling Quiz · 4.1.1.8 · 20 questions
- Parameters and returning values Quiz · 4.1.1.11 · 20 questions
- Local and global variables Quiz · 4.1.1.13 · 20 questions
- Stack frames in subroutine calls Quiz · 4.1.1.15 · 20 questions