4.1.1.10 Subroutines (procedures/functions) and 4.1.1.11 Parameters of subroutines Flashcards

1
Q

What is a function?

A

A subroutine that’s called as part of an expression in a program, which returns a single value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a procedure?

A

A subroutine called and executed which does not have to return a value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a parameter?

A

An item of data given to a procedure/function which is then given a value inside the subroutine and is used as a variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s the benefits of using subroutines / modular programming?

A

You can write a subroutine at a time which you can then easily test. Other people can understand the program more clearly and they can write more subroutines into your program without breaking it. You can reuse modules from other programs and replace them without affecting the whole program.
Code can be used ‘repeatedly’ within the same program ;
To make program debugging/testing/maintenance easier

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the differences between a function and procedure?

A

A function returns a value, a procedure doesn’t have to.

A function appears in an expression but a procedure forms a statement of it’s own.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the importance of libraries?

A

A library is a collection of precompiled routines in a programming language. They are tried and tested so should reduce debugging and save time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a subroutine

A

A sequence of instructions that can be called at any point after declaration in the program, making it an ‘out of line’ section of code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Procedures and functions are often self-contained. What is meant by the term self-contained in this context?

A

Do not use any global variables// use only local variables and/or parameters;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Give one reason why the use of global variables may introduce program bugs .

A

Local and global variables with the same name can be misidentified//difficult to test individual procedures/ functions//
Not clear that as a side-effect of executing procedure/function a global variable could change its value;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly