CHAPTER 4 (1-30) REVIEW QUESTIONS Flashcards

1
Q
  1. 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. Can an if statement test expressions other than relational expressions? Explain.
A
  1. 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. Briefly describe how the && operator works.
A
  1. It takes two expressions as operands and creates a single expression that is true only when both subexpressions are true.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. Briefly describe how the || operator works.
A
  1. It takes two expressions as operands and creates a single expression that is true when either of the subexpressions are true.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. Why are the relational operators called relational?
A
  1. 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. Why do most programmers indent the conditionally executed statements in a decision structure?
A
  1. 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. 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
  1. relational
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. A relational expression is either __________ or __________.
A
  1. true, false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. The value of a relational expression is 0 if the expression is __________ or 1 if the expression is __________.
A
  1. false, true
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. The if statement regards an expression with the value 0 as __________.
A

false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. The if statement regards an expression with a nonzero value as __________.
A
  1. true
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
  1. For an if statement to conditionally execute a group of statements, the statements must be enclosed in a set of __________.
A

braces

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
  1. 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
  1. true, false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
  1. The trailing else in an if/else if statement has a similar purpose as the __________ section of a switch statement.
A
  1. default
17
Q
  1. The if/else if statement is actually a form of the __________ if statement.
A
  1. nested
18
Q
  1. If the sub-expression on the left of the __________ logical operator is false, the right sub-expression is not checked.
A
  1. &&
19
Q
  1. If the sub-expression on the left of the __________ logical operator is true, the right sub-expression is not checked.
A
  1. ||
20
Q
  1. The __________ logical operator has higher precedence than the other logical operators.
A
  1. !
21
Q
  1. The logical operators have __________ associativity.
A
  1. left-to-right
22
Q
  1. The __________ logical operator works best when testing a number to determine if it is within a range.
A
  1. &&
23
Q
  1. The __________ logical operator works best when testing a number to determine if it is outside a range.
A
  1. ||
24
Q
  1. A variable with __________ scope is only visible when the program is executing in the block containing the variable’s definition.
A
  1. block
25
Q
  1. You use the __________ operator to determine whether one string object is greater then another string object.
A
  1. >
26
Q
  1. An expression using the conditional operator is called a(n) __________ expression.
A
  1. conditional
27
Q
  1. The expression that is tested by a switch statement must have a(n) __________ value.
A
  1. integer
28
Q
  1. The expression following a case statement must be a(n) __________ __________.
A
  1. integer constant
29
Q
  1. A program will “fall through” a case section if it is missing the __________ statement.
A
  1. break
30
Q
  1. What value will be stored in the variable t after each of the following statements executes?A) t = (12 > 1); __________B) t = (2 < 0); __________C) t = (5 = = (3 * 2)); __________D) t = (5 = = 5); __________
A
  1. A) 1B) 0 C) 0D) 1