levo

Fundamentals of Programming

Subroutines, parameters and return values

  • 3 things to know
  • Paper 1
Start revising · £5/month

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.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

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

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

A driver is .
softwarehardwarestorage

Blank Blitz consolidates the facts

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

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

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

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

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.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.