Control Flow Flashcards

1
Q

What is an execution path

A

The specific sequence of statements the CPU executes when a program is run

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

What is a straight line program

A

A program that takes the same execution path every time it is run

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

What is a dangling else

A

When it is ambiguous which if statement an else statement is connected with. Dangling else are matched with the most recent if in the same block

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

What is a null statement

A

;

A statement that consists of just a semicolon. It does nothing.

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

Why are switch statements better than a long chain of if/else that could be switch

A

in a switch statement only the one case is executed it doesn’t have to go through all the cases

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

What is the only type switch statements work with

A

integral type

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

What is a fallthrough

A

When execution flows from a statement underneath a label into the statements underneath a subsequent label.

This happens when there is no break or return statement under the case

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

How do we prevent fallthrough

A

Use a break or return statement

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

what is [[fallthrough]] attribute

A

indicates intentional fallthrough

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

What is a Goto statement and why should they be avoided?

A

It allows the program to jump to somewhere else in the code. They should be avoided as they can create spaghetti code

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

What is a halt

A

A statement that lets us terminate the program

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

What is normal termination

A

When the program exited in an expected way

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

What is a status code

A

Indicates whether the program succeeded or not

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

Explain std::exit()

A

A halt that is called at the end of main. It does some cleanup but does not cleanup any local variables or unwind the call stack

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

Abnormal termination

A

When the program encountered an unexpected error and had to be shut down. E.g. can be done with std::abort

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

Deterministic algorithm

A

Given the same input it will always produce the same output

17
Q

Pseudo Random number generator

A

An algorithm that generates a sequence of numbers whose properties simulate a sequence of random numbers.

18
Q

PRNG seed

A

An initial value or set of values provided to initialise the state of the PRNG

19
Q

Underseeded PRNG

A

When the size of the seed is smaller than the size of the state of the PRNG.

20
Q

PRNG period

A

Length of sequence before it begins to repeat itself

21
Q

Random number distribution

A

Converts the output of a PRNG into some other distribution of numbers

22
Q

Uniform distribution

A

A random number distribution that produces outputs between two numbers X and Y with equal probability