Control Flow Flashcards
What is an execution path
The specific sequence of statements the CPU executes when a program is run
What is a straight line program
A program that takes the same execution path every time it is run
What is a dangling else
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
What is a null statement
;
A statement that consists of just a semicolon. It does nothing.
Why are switch statements better than a long chain of if/else that could be switch
in a switch statement only the one case is executed it doesn’t have to go through all the cases
What is the only type switch statements work with
integral type
What is a fallthrough
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 do we prevent fallthrough
Use a break or return statement
what is [[fallthrough]] attribute
indicates intentional fallthrough
What is a Goto statement and why should they be avoided?
It allows the program to jump to somewhere else in the code. They should be avoided as they can create spaghetti code
What is a halt
A statement that lets us terminate the program
What is normal termination
When the program exited in an expected way
What is a status code
Indicates whether the program succeeded or not
Explain std::exit()
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
Abnormal termination
When the program encountered an unexpected error and had to be shut down. E.g. can be done with std::abort