slr23 - programming constructs Flashcards

1
Q

Describe sequence

A

The default mode for code to work in: executing instruction one after another

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

Describe selection

A

Allows a program to change direction depending on the outcome of a condition

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

Describe iteration

A

Also called looping: enables us to repeat lines of code

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

What is recursion

A

When a subroutine calls itself from within its own subroutine

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

What are the features of recursion

A

Contains a stopping condition
For any value other than the stopping condition the subroutine should stop itself
The stopping condition should be reachable in a finite amount of times

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

What causes a stack overflow in relation to recursion

A

When a recursive function calls itself indefinitely

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

When is recursion used

A

Tree traversal algorithems

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

What is the scope of a variable

A

From where in the program it can be accessed from

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

What is a local variable

A

A var that can only be accessed from inside of a specific subroutine

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

What is a global variable

A

A var that can be accessed from anywhere in the program

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

Why is it sometimes better to use local variables

A

In large programs global vars can be confusing
Global vars are not deleted after they have been used therefore they take up more space in memory

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

What is a function

A

A block of code that:
Takes in parameters
Performs a set task
returns a value

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

What is a procedure

A

A block of code that:
Takes in parameters
Performs a set task

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

What are parameters

A

Values that are passed into a function

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

Passing by reference

A

References the location in memory
This means that the value can be changed

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

Describe passing by value

A

Creates a copy of the variable
The original value cannot change