2.2.1 (Programming Constructs) Flashcards

(26 cards)

1
Q

What is recursion?

A

When a subroutine (often a function) calls itself within its own subroutine​

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

What are the characteristics of a recursive subroutine?

A

-Contains a stopping condition which should be reachable within a finite number of times​

-Subroutine should call itself (recursion) for any input value other than the stopping condition​

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

What would happen if a recursive subroutine called itself indefinitely?

A

It would run out of memory causing the program to crash (STACK OVERFLOW)​

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

What are the drawbacks of recursion?

A

High memory usage​ as a new version of the function is created every time it is called

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

What are some examples of when recursion is used?

A

-Tree traversal​

-Performing a flood fill in a graphics application

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

What is scope?

A

Where a variable is accessible inside a code

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

What are local variables?

A

Variables declared inside a subroutine and are only accessible by that subroutine. They are created when the subroutine is called and destroyed when the subroutine ends.

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

What are global variables?

A

Variables that are declared outside of any subroutines. They are accessible throughout the program, created when the program starts and destroyed when the program ends.​

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

What are the drawbacks of using global variables?

A

-Increases memory usage (as they are used until full program execution is over)

-Alterations within functions may have unwanted side effects elsewhere in the program

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

What are the advantages of using local variables?

A

-Easier for different programmers to work on the same program – procedures will not conflict if variables with
the same name are used​

-Easier to debug programs (code in a procedure is self-contained)​

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

What is a drawback of using local variables?

A

May slow execution as memory is allocated dynamically when needed

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

What is modularity?

A

The concept of breaking problems down into smaller chunks​

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

What is the role of a procedure?

A

-Performs a set task​
-Takes in zero, one or more parameters

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

What is the role of a function?

A

-Performs a set task​
-Takes in zero, one or more parameters​
-Returns a value​

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

What are the PROs of procedures?

A

-Makes program easier to read & debug​

-Facilitates use of local variables​

-Enables different programmers to work on different parts of the code​

-Allows routines to be reused in other programs​

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

What are the PROs of functions?

A

-Can be called as often as needed, reducing the need for duplicated code​

-Building blocks that enable larger programs to be written using reusable code routines​

-Can be stored in libraries for other programmers to use in their programs. Library functions:​
-Are already tested​
-Make use of another programmer’s skill​
-Can be written in other languages as they are already compiled

17
Q

What happens when parameters are passed by value?

A

The value created for the subroutine being called is a copy of the original​

Once it is passed in, the parameter is held in a separate memory location -> only available to the subroutine​

Copy is now a local variable of that subroutine (if something is done to the value of the copied variable, the value of the original variable remains unaffected)

18
Q

What happens when parameters are passed by reference?

A

A pointer that contains the memory address of the original variable is created -> any change to the value from within the subroutine will also affect the value of the original variable

19
Q

What is an IDE?

A

A program that provides a set of tools & related functionality designed to maximise a programmer’s productivity​

20
Q

What are some features of IDEs?

A

Syntax highlighting​ —-> help identify key elements

Autocompletion​ —-> start typing command and it fills in the rest

Automatic indentation​ —-> indents code automatically within structures to avoid errors

Code editors —> text area where code can be entered directly into IDE (often supports additional features like syntax highlighting, autocomplete, & automatic indentation​)

Error diagnostics —> reports errors in the code & where they can be found​

Run-time environments —> software that supports the execution & running of programs; allows programmers to easily run code during development​

Translators —> program that converts high-level code into executable, machine code​

Auto-documentation —> tracks declared variables, modules, & other special programmer comments with a view to producing documentation that aids in program maintenance, debugging & support​

​Breakpoints —-> stop the program at a set point to check variables

Variable watch window —-> display the values of the variables while the program is run

21
Q

What are the PROs of Object-Oriented Programming:?

A

Various game items can be easily represented as objects​

Inheritance can be used to create specialised versions of classes​

You can easily spin up extra copies of common objects (as code is organised into modular, reusable objects)​

22
Q

What are the benefits of using global variables?

A

-Variable doesn’t need passing as a parameter

-Don’t need to return a value

-Can be accessed from anywhere function/ anywhere in the program

23
Q

What is a parameter?

A

An item of data passed to a subroutine, used as a variable within the subroutine

24
Q

What is a procedural programming language?

A

A high-level language that gives a series of instructions in a logical order

25
What is a variable?
Identifier/Name of a memory location used to store data
26
Explain ‘scope’ in relation to variables within a program that calls several procedures.
-Global variables are defined at the start of a program -Global variables can be used everywhere in the program -Local variables can only be used in a procedure in which they are declared -Local variables cease to exist once the procedure they are in is finished -Local variables with the same name as global variables take precedence over the value in the global variable -Local variables within two different procedures will not interfere with one another