CHAPTER 4 (1-30) REVIEW QUESTIONS Flashcards
1
Q
- In an if/else if statement, what is the purpose of a trailing else ?
A
The trailing else provides code that is executed when none of the conditions in the if/else if statement are true.
2
Q
- Describe the difference between the if/else if statement and a series of if statements.
A
In an if/else if statement, the conditions are tested until one is found to be true. The conditionally executed statement(s) are executed and the program exits the if/else if statement. In a series of if statements, all of the if statements execute and test their conditions because they are not connected
3
Q
- What is a flag and how does it work?
A
A flag is a Boolean variable signaling that some condition exists in the program. When the flag is set to false it indicates the condition does not yet exist. When the flag is set to true it indicates that the condition does exist.
4
Q
- Can an if statement test expressions other than relational expressions? Explain.
A
- Yes. The if statement can test any value that yields a Boolean value (true or false) or a numeric value. When testing a numeric expression, a nonzero numeric value is considered true, and the value 0 is considered false.
5
Q
- Briefly describe how the && operator works.
A
- It takes two expressions as operands and creates a single expression that is true only when both subexpressions are true.
6
Q
- Briefly describe how the || operator works.
A
- It takes two expressions as operands and creates a single expression that is true when either of the subexpressions are true.
7
Q
- Why are the relational operators called relational?
A
- Because they test for specific relationships between items. The relationships are greater-than, less-than, equal-to, greater-than or equal-to, less-than or equal-to, and not equal-to.
8
Q
- Why do most programmers indent the conditionally executed statements in a decision structure?
A
- It visually sets the conditionally-executed statements apart from the surrounding code. This is so you can easily identify the code that is conditionally-executed.
9
Q
- An expression using the greater-than, less-than, greater-than-or-equal to, less-than-orequal-to, equal, or not-equal to operator is called a(n) __________ expression.
A
- relational
10
Q
- A relational expression is either __________ or __________.
A
- true, false
11
Q
- The value of a relational expression is 0 if the expression is __________ or 1 if the expression is __________.
A
- false, true
12
Q
- The if statement regards an expression with the value 0 as __________.
A
false
13
Q
- The if statement regards an expression with a nonzero value as __________.
A
- true
14
Q
- For an if statement to conditionally execute a group of statements, the statements must be enclosed in a set of __________.
A
braces
15
Q
- In an if/else statement, the if part executes its statement or block if the expression is __________, and the else part executes its statement or block if the expression is__________.
A
- true, false