Module 5 Flashcards
(37 cards)
If none of the conditions is true in an if-ladder then the final else statement will be executed.
True
Which program structure is used to repeat a set of statements?
repetition
The switch case is a clean and efficient method of handling the complexity of using lengthy if-ladder structure.
True
Break statements are used when you want your program-flow to come out of the switch body.
True
When the variable being switched on is equal to a case, the statements following that case will execute until a break statement is reached.
True
A switch construct can be used with which of the following types of variables.
- int, float, char
- int
- int, char
- Any basic datatype
int, char
Nested switch statements should be avoided as it makes program more complex and less readable.
True
When C++ reaches a break keyword, it continues to test other cases.
False
Whether the indentation exists or not, the compiler will, by default, associate an else with the closest previous unpaired if.
True
The constant-expression for a case must be of different data type as the variable in the switch.
False
Whenever a break statement is encountered in the switch body, the execution flow would directly come out of the switch, ignoring rest of the cases
True
When you have the default keyword in your switch, you are required to place a break statement.
False
If one of the conditions in an if-ladder true, the statement associated with that if is executed, and continue testing the conditions in the rest of the ladder.
False
Which of the following can replace a simple if-else construct?
- ternary operator
- do-while loop
- for loop
- while loop
ternary operator
How many choices are possible when using a switch case statement?
1 or more
In switch, the value of the expression is compared with the values of each case.
True
In switch if there is a match, the associated block of code is executed
True
The default keyword must be used as the last statement in the switch.
True
Switch case statement is used when you only have one condition.
False
If no break appears, the flow of control will fall through to subsequent cases until a break is reached
True
The default case can be used for performing a task when none of the cases is true
True
The break statement causes an exit ________
from the innermost loop or switch.
Which of the following is not true about switch statement?
- The constant-expression for a case must be the same data type as the variable in the switch
- When a break statement is reached, the flow of control will fall through to subsequent cases until a break is reached.
- A switch statement allows a variable to be tested for equality against a list of values
- The expression used in a switch statement must have an integral or enumerated type.
When a break statement is reached, the flow of control will fall through to subsequent cases until a break is reached.
A switch statement allows a variable to be tested for inequality against a list of values
False