levo

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.

Your recallNot started
Key term

What is the difference between a procedure and a function?

Process

What does passing a parameter by value mean?

Process

How does a subroutine return a value to the calling routine?

Questions from this subtopic

Each one with the model answer underneath.

  1. 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. 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. 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. 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. 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. 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.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

Fundamentals of Programming
Fundamentals of Data Structures
Fundamentals of Algorithms
Theory of Computation

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

A driver is .
softwarehardwarestorage

Blank Blitz makes facts automatic

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

AThe integer 5 is 0101.
B0.75 is 1/2 + 1/4.
CThe fraction bits are 1100.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

Head means the first single element of a non-empty list.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

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.