Deck 4: Selection

Full screen (f)
exit full mode
Question
The term "flow of control" refers to the order in which a program's statements are executed.
Use Space or
up arrow
down arrow
to flip the card.
Question
A relational expression consists of a boolean operator that compares two operands.
Question
In C, relational expressions are evaluated to yield a boolean result.
Question
In C, character data cannot be compared using relational operators.
Question
The && operator has a right-to-left associativity.
Question
The evaluation feature for the && and || operators that makes the evaluation of an expression stop as soon as it is definitively determined that an expression is true or false is known as short-circuit evaluation.
Question
The ! operator is an unary operator.
Question
The expression:
(6 * 3 == 36 / 2) && (13 < 3 * 3 + 4) || !(6 - 2 < 5)
evaluates to 1.
Question
The simplest C selection statement is the one-way if statement.
Question
The use of braces to enclose a set of individual statements creates a single block of statements, which may be used anywhere in a C program in place of a single statement.
Question
In C any expression can be tested within a selection statement, be it a relational, arithmetic, or assignment expression, or even a function call.
Question
Within a selection statement, an expression that evaluates to 0 or less is considered as false, while any positive is considered as true.
Question
A common practice for some programmers is to place the opening brace of a compound statement on the same line as the if and else statements.
Question
The following statement prints "You lose!" on the screen;
int num = -1;
if (num)
printf("Bingo!");
else
printf("You lose!");
Question
If you inadvertently use an assignment symbol, =, in place of the relational symbol, == in a relational expression, the compiler will flag this with either a warning or error message.
Question
Generally, the most useful nested if statement occurs when a second if-else statement is placed within the else part of an if-else statement.
Question
A nested if construction in which each nested if is written in the same line as the previous else is called an if-else chain, and is used extensively in many programming problems.
Question
Indentation used within an if-else is critical to ensure that the code compiles correctly.
Question
The compiler will, by default, associate an else with the closest previous unpaired if, unless braces are used to alter this default pairing.
Question
One of the main advantages of using a switch statement is that it avoids using the equality operator, ==.
Question
One of the main disadvantages of using a switch statement is that it requires the use of braces for compound internal statements.
Question
The switch statement usually results in more complex code than an equivalent if-else chain.
Question
Any number of case labels may be contained within a switch statement, in any order.
Question
In a switch statement, if the break statements are omitted, all cases following the matching case value, including the default case, are executed.
Question
When an executing program encounters a(n) ____ statement, the condition is evaluated to determine its numerical value, which is then interpreted as either true or false.

A)switch
B)break
C)if
D)else
Question
Relational expressions are also known as ____.

A)conditions
B)boolean expressions
C)logical expressions
D)if-else expressions
Question
The logical AND operator is ____.

A)||
B)&&
C)!
D)%%
Question
The logical NOT operator is ____.

A)||
B)&&
C)!
D)%%
Question
When the ____ operator is used with two expressions, the condition is true only if both expressions are true by themselves.

A)||
B)&&
C)!
D)%%
Question
When the ____ operator is used with two expressions, the resulting condition is true if either one or both of the two expressions are true.

A)||
B)&&
C)!
D)%%
Question
The ____ operator is used to change an expression to its opposite state.

A)||
B)&&
C)!
D)%%
Question
Which of the following operators has right to left associativity?

A)!
B)*
C)&&
D)||
Question
A ____ statement is one or more statements contained between braces.

A)conditional
B)nested
C)flow
D)compound
Question
What will the following program print on screen?
Int age = 0;
If (age = 40)
Printf("Happy Birthday!");
Else
Printf("Sorry");

A)Happy Birthday!
B)Sorry
C)Runtime error.
D)Nothing; the program will not compile.
Question
What will the following program print on screen?
Int age = 40;
If (age = 40)
Printf("Happy Birthday!");
Else
Printf("Sorry");

A)Happy Birthday!
B)Sorry
C)Runtime error.
D)Nothing; the program will not compile.
Question
What will the following program print on screen?
Int tenure = -5;
If (tenure + 5)
Printf("Congratulations!");
Else
Printf("Sorry");

A)Congratulations!
B)Sorry
C)Runtime error.
D)Nothing; the program will not compile.
Question
What will the following program print on screen?
Int tenure = -10;
If (tenure + 5)
Printf("Congratulations!");
Else
Printf("Sorry");

A)Congratulations!
B)Sorry
C)Runtime error.
D)Nothing; the program will not compile.
Question
The use of ____ in a C program will result in a compiler error.

A)if (age == 40)
B)if (40 == age)
C)if (age = 40)
D)if (40 = age)
Question
Including one or more if-else statements within an if or if-else statement is referred to as a ____ if statement.

A)compound
B)nested
C)multiway
D)short-circuit
Question
A ____ statement is a specialized selection statement that can be used in place of an if-else chain where exact equality to one or more integer constants is required.

A)case
B)break
C)switch
D)nested if
Question
In a switch statement, the word ____ is optional and operates the same as the last else in an if-else chain.

A)if
B)break
C)case
D)default
Question
It is a good practice to terminate the last case in a switch statement with a ____.

A)switch
B)break
C)default
D)case
Question
One aspect of ____ programming is to check for improper data before an attempt is made to process it further.

A)defensive
B)extreme
C)robust
D)user-friendly
Question
____ is not a relational operator.

A) ==
B) >
C) !=
D) ||
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/44
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 4: Selection
1
The term "flow of control" refers to the order in which a program's statements are executed.
True
2
A relational expression consists of a boolean operator that compares two operands.
False
3
In C, relational expressions are evaluated to yield a boolean result.
False
4
In C, character data cannot be compared using relational operators.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
5
The && operator has a right-to-left associativity.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
6
The evaluation feature for the && and || operators that makes the evaluation of an expression stop as soon as it is definitively determined that an expression is true or false is known as short-circuit evaluation.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
7
The ! operator is an unary operator.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
8
The expression:
(6 * 3 == 36 / 2) && (13 < 3 * 3 + 4) || !(6 - 2 < 5)
evaluates to 1.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
9
The simplest C selection statement is the one-way if statement.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
10
The use of braces to enclose a set of individual statements creates a single block of statements, which may be used anywhere in a C program in place of a single statement.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
11
In C any expression can be tested within a selection statement, be it a relational, arithmetic, or assignment expression, or even a function call.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
12
Within a selection statement, an expression that evaluates to 0 or less is considered as false, while any positive is considered as true.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
13
A common practice for some programmers is to place the opening brace of a compound statement on the same line as the if and else statements.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
14
The following statement prints "You lose!" on the screen;
int num = -1;
if (num)
printf("Bingo!");
else
printf("You lose!");
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
15
If you inadvertently use an assignment symbol, =, in place of the relational symbol, == in a relational expression, the compiler will flag this with either a warning or error message.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
16
Generally, the most useful nested if statement occurs when a second if-else statement is placed within the else part of an if-else statement.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
17
A nested if construction in which each nested if is written in the same line as the previous else is called an if-else chain, and is used extensively in many programming problems.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
18
Indentation used within an if-else is critical to ensure that the code compiles correctly.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
19
The compiler will, by default, associate an else with the closest previous unpaired if, unless braces are used to alter this default pairing.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
20
One of the main advantages of using a switch statement is that it avoids using the equality operator, ==.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
21
One of the main disadvantages of using a switch statement is that it requires the use of braces for compound internal statements.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
22
The switch statement usually results in more complex code than an equivalent if-else chain.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
23
Any number of case labels may be contained within a switch statement, in any order.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
24
In a switch statement, if the break statements are omitted, all cases following the matching case value, including the default case, are executed.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
25
When an executing program encounters a(n) ____ statement, the condition is evaluated to determine its numerical value, which is then interpreted as either true or false.

A)switch
B)break
C)if
D)else
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
26
Relational expressions are also known as ____.

A)conditions
B)boolean expressions
C)logical expressions
D)if-else expressions
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
27
The logical AND operator is ____.

A)||
B)&&
C)!
D)%%
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
28
The logical NOT operator is ____.

A)||
B)&&
C)!
D)%%
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
29
When the ____ operator is used with two expressions, the condition is true only if both expressions are true by themselves.

A)||
B)&&
C)!
D)%%
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
30
When the ____ operator is used with two expressions, the resulting condition is true if either one or both of the two expressions are true.

A)||
B)&&
C)!
D)%%
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
31
The ____ operator is used to change an expression to its opposite state.

A)||
B)&&
C)!
D)%%
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
32
Which of the following operators has right to left associativity?

A)!
B)*
C)&&
D)||
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
33
A ____ statement is one or more statements contained between braces.

A)conditional
B)nested
C)flow
D)compound
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
34
What will the following program print on screen?
Int age = 0;
If (age = 40)
Printf("Happy Birthday!");
Else
Printf("Sorry");

A)Happy Birthday!
B)Sorry
C)Runtime error.
D)Nothing; the program will not compile.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
35
What will the following program print on screen?
Int age = 40;
If (age = 40)
Printf("Happy Birthday!");
Else
Printf("Sorry");

A)Happy Birthday!
B)Sorry
C)Runtime error.
D)Nothing; the program will not compile.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
36
What will the following program print on screen?
Int tenure = -5;
If (tenure + 5)
Printf("Congratulations!");
Else
Printf("Sorry");

A)Congratulations!
B)Sorry
C)Runtime error.
D)Nothing; the program will not compile.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
37
What will the following program print on screen?
Int tenure = -10;
If (tenure + 5)
Printf("Congratulations!");
Else
Printf("Sorry");

A)Congratulations!
B)Sorry
C)Runtime error.
D)Nothing; the program will not compile.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
38
The use of ____ in a C program will result in a compiler error.

A)if (age == 40)
B)if (40 == age)
C)if (age = 40)
D)if (40 = age)
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
39
Including one or more if-else statements within an if or if-else statement is referred to as a ____ if statement.

A)compound
B)nested
C)multiway
D)short-circuit
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
40
A ____ statement is a specialized selection statement that can be used in place of an if-else chain where exact equality to one or more integer constants is required.

A)case
B)break
C)switch
D)nested if
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
41
In a switch statement, the word ____ is optional and operates the same as the last else in an if-else chain.

A)if
B)break
C)case
D)default
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
42
It is a good practice to terminate the last case in a switch statement with a ____.

A)switch
B)break
C)default
D)case
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
43
One aspect of ____ programming is to check for improper data before an attempt is made to process it further.

A)defensive
B)extreme
C)robust
D)user-friendly
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
44
____ is not a relational operator.

A) ==
B) >
C) !=
D) ||
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 44 flashcards in this deck.