AQA A-Level Computer Science 7517
Fundamentals of Programming
Fundamentals of Data Structures
Fundamentals of Algorithms
Theory of Computation
Fundamentals of Data Representation
Fundamentals of Computer Systems
Fundamentals of Computer Organisation and Architecture
Fundamentals of Communication and Networking
Consequences of Uses of Computing
Systematic Approach to Problem Solving
Fundamentals of Databases
Big Data
Fundamentals of Programming
Subroutines, parameters and return values
- 3 things to know
- Paper 1
Overview
Recall questions on procedures against functions, formal and actual parameters, passing by value and by reference, and what a call does to the flow of control.
What you need to know
Answer each one before you reveal it.
What does passing a parameter by value mean?
How does a subroutine return a value to the calling routine?
Questions from this subtopic
Each one with the model answer underneath.
- 1
What is a subroutine?
Model answer
A named block of code written out of line, that is written once away from the main flow of the program, and executed by simply writing its name in a program statement. Writing its name is called calling it.
- 2
What is the difference between a procedure and a function?
Model answer
A function returns a value to the point at which it was called, so a call to it can be used inside an expression, as in total = total + areaOf(shape). A procedure carries out a task and returns no value, so a call to it stands alone as a statement, as in printReport(). Both may take parameters.
- 3
What does breaking a program into subroutines buy you?
Model answer
A block of code needed in several places is written once and called wherever it is needed, so the program is shorter and a correction has to be made only once. A large problem is broken into smaller named parts that can each be understood, written, tested and debugged on their own, and shared out among a team. A tested subroutine can be reused in other programs or collected into a library. The main program becomes a readable outline of what happens rather than a mass of detail, which makes maintenance easier.
- 4
Describe what happens to the flow of control when a subroutine is called.
Model answer
Execution leaves the calling code at the call statement and continues at the first statement of the subroutine. When the subroutine finishes, or reaches a return, control passes back to the calling code and continues at the statement immediately after the call, with any returned value substituted into the expression that called it.
- 5
What is the difference between a built-in subroutine and a user-defined one?
Model answer
A built-in subroutine is supplied ready-made with the language or in one of its libraries, such as a square-root function or a string length function, and you use it without knowing how it works. A user-defined subroutine is one the programmer writes. Both are called in exactly the same way.
- 6
What is a parameter, and what is the difference between a formal and an actual parameter?
Model answer
A parameter is a value passed into a subroutine so that the same code can work on different data. The formal parameters are the names listed in the subroutine's definition, which act as variables inside it. The actual parameters, or arguments, are the values supplied in a particular call. They are matched up in order, and their number and types must correspond.
Other ways to work this
The same content, four other ways.
What is inside Levo
Six ways to work the same material.
Every question in Fundamentals of Programming, on a schedule.
Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.
Or £46 a year, about £3.83 a month. Cancel anytime.