Sub Programs Flashcards

1
Q

What can sub programs be used for?

A

Save time and to simplify code.

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

What are procedures?

A
  • sets of instructions stored under one name

- when you want all the instructions executed you only need to call the name of the procedure

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

How are functions different from procedures?

A

Functions always return a value.

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

Why are procedures and functions useful when you have sets of instructions that you need to repeat in different places within a program?

A

They give your program more structure and readability whilst cutting down on the amount of code you actually need to write.

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

What has common procedures and functions built into them?

A

High level programming languages, but if you want something more specific you can create them yourself.

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

What are parameters?

A

Special variables used to pass values into a sub program. For each parameter you can specify a name, a data type and a default value.

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

What are arguments?

A

Arguments are the actual values that the parameters take when the sub program is called.

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

What do functions do?

A

Take at least one parameter and they must always return a value.

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

What should happen when a function is called?

A

It should be assigned to a variable or used in a statement otherwise the value that it returns will not be stored anywhere and will be lost.

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

What is a variables scope?

A

The scope of a variable tells you which parts of the program the variable can be used in.

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

What is a local variable?

A

Can only be used within the structure they’re declared in - they have a local scope.

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

What is a global variable?

A

Can used be any time after their declaration - they have a global scope.

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

What are variables declared inside a subprogram?

A

Local variables. They are invisible to the rest of the program. This means they can’t be used outside the function.

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

What is an advantage of a local variable?

A

The scope only extends to the subprogram they’re declared in, so they can’t affect or be affected by anything outside the sub program. It also doesn’t matter if you use the same variable name as a local variable defined somewhere else in the program.

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

How can variables in the main body of a program be made into global variables?

A

Using the ‘global’ keyword - these variables can then be used anywhere in the program. However it can be difficult to keep track of the value of global variables in larger programs.

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