Module 5 Flashcards

(37 cards)

1
Q

If none of the conditions is true in an if-ladder then the final else statement will be executed.

A

True

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

Which program structure is used to repeat a set of statements?

A

repetition

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

The switch case is a clean and efficient method of handling the complexity of using lengthy if-ladder structure.

A

True

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

Break statements are used when you want your program-flow to come out of the switch body.

A

True

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

When the variable being switched on is equal to a case, the statements following that case will execute until a break statement is reached.

A

True

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

A switch construct can be used with which of the following types of variables.

  • int, float, char
  • int
  • int, char
  • Any basic datatype
A

int, char

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

Nested switch statements should be avoided as it makes program more complex and less readable.

A

True

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

When C++ reaches a break keyword, it continues to test other cases.

A

False

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

Whether the indentation exists or not, the compiler will, by default, associate an else with the closest previous unpaired if.

A

True

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

The constant-expression for a case must be of different data type as the variable in the switch.

A

False

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

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

A

True

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

When you have the default keyword in your switch, you are required to place a break statement.

A

False

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

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.

A

False

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

Which of the following can replace a simple if-else construct?

  • ternary operator
  • do-while loop
  • for loop
  • while loop
A

ternary operator

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

How many choices are possible when using a switch case statement?

A

1 or more

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

In switch, the value of the expression is compared with the values of each case.

17
Q

In switch if there is a match, the associated block of code is executed

18
Q

The default keyword must be used as the last statement in the switch.

19
Q

Switch case statement is used when you only have one condition.

20
Q

If no break appears, the flow of control will fall through to subsequent cases until a break is reached

21
Q

The default case can be used for performing a task when none of the cases is true

22
Q

The break statement causes an exit ________

A

from the innermost loop or switch.

23
Q

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.
A

When a break statement is reached, the flow of control will fall through to subsequent cases until a break is reached.

24
Q

A switch statement allows a variable to be tested for inequality against a list of values

25
Which of the following must be present in the switch construct?
Expression in ( ) after switch
26
The constant-expression for a case may be a floating point number.
False
27
Nesting of switch statements is not allowed, which means you can have switch statements inside another switch.
False
28
To make the multiple statements become compound statement, enclosed the statements with brackets [].
False
29
Program control structure in which statements are performed next based on a condition is selection.
True
30
Each case is followed by the value to be compared to and a semicolon.
False
31
Which of the following is not a program control structure?
instantiation
32
A break can save a lot of execution time because it "ignores" the execution of all the rest of the code in the switch block.
True
33
Whenever a default keyword is encountered in the switch body, the execution flow would directly come out of the switch, ignoring rest of the cases
False
34
If one of the conditions in an if-ladder true, the statement associated with that if is executed, and does not continue testing the conditions in the rest of the ladder.
True
35
The constant-expression for a case may be a string or float data type as the variable in the switch.
False
36
The compiler by default associates an else with the closest previous unpaired if whether the indentation exists or not.
True
37
The break statement causes an exit from the innermost loop or switch.
True