Programming Techniques Flashcards

1
Q

What are the three programming constructs?

A

Sequence,
Selection (Branching),
Iteration

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

What is Sequence?

A

Executing Instructions one after another in order (e.g. Line 1, Line 2, Line 3, etc.)

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

What is Selection?

A

Conditional Statements that can change the flow and order of execution in code (e.g. if and elif in python)

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

What is Iteration?

A

Repeating the same block of code multiple times (for and while in python)

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

What is a Boolean Expression?

A

An evaluative statement that results in a boolean output (e.g. num1 == num2)

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

What is the difference between a pre-test loop and post-test loop?

A

Pre-test loop: the conditional test is done before the body of the loop is executed
Post-test loop: the conditional test is done after the body of the loop is executed

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

What is the usefulness of a switch/match case statement?

A

Keeps code cleaner by simplifying the many if statements with simple to read cases
e.g.
switch(value) {
case 1:
//Code
break;
}

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

What is a global variable?

A

A variable that is created at the start of a program and exists until the end, this variable is stored in the Heap

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

What is a local variable?

A

A variable that is created at the start of a sub-program and is freed from memory when the sub-program ends, this variable is stored in the Stack

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

What is the stack?

A

A section of program memory that allows for values to be pushed onto it and popped off of it, it is a first in, last out data structure (like a stack of plates)

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

What is the heap?

A

A defined section of memory that holds variables placed within it at the pointed to location, no order of data in and out

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

Why would we want to and not want to use global variables?

A

Global variables could be used for data that is commonly accessed across the program like score, however can be confusing when there are loads of them especially in larger projects that span 1000s of lines and many different files and modules

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

What is garbage collection?

A

When the high level language’s runtime environment handles local variables pushing them onto the stack when a subroutine starts and popping them off the stack when the subroutine exits

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

What actually happens to free a section of the stack?

A

The stack pointer decrements preventing the program from accessing the “removed” data, which will be overridden when more data is pushed onto the stack

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