C++ CPT-232 Chapter 4 Review questions (1-30 & 42-58)
16. The trailing else if an if/else if statement has a similar purpose as the ____ section of a switch statement.
Default
52. y < x is the same as x >=y
F
55
F
When an if statements is nested in the else part of another statement, as in an if/else if, the only time the inner if is executed is when the expression of the outer if is true.
F
. T or F The = operator and the == operator perform the same operation when used in a Boolean expression.
FALSE
46. It's safe to assume that all uninitialized variables automatically start with - as their value.
FALSE
T or F A variable defined in an inner block may not have the same name as a variable defined in the outer block.
FALSE
12. The if statement regards an expression with the value 0 as
False
11. The value of a relational expression is 0 if the expression is _____ or 1 if the expression is ____.
False/ true
30. Write an if statement that assigns 100 to x when y is equal to 0.
If (y == 0) x = 100.
1. Describe the difference between the if/else statement and a series of if statements.
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.
13. The if statement regards an expression with a nonzero value as _____.
True
10. A relational expression is either ____ or ____.
True or False
58
cin >> score1 >>score2 >> score3>>endl; cin's don't use endl. That's only for cout's.
2. In an if/else if statement, what is the purpose of a trailing else?
executed when all the preceding conditional expressions are false
19. The ____ logical operator has higher precedence than the other logical operators.
!
18. If the subexpression on the left of the ____ logical operator is false, the right subexpression is not checked.
&&
21. The ____ logical operator works best when testing a number to determine if it is within range.
&&
24. You use the ____ operator to determine whether one string object is greater than another string object.
>
8. Why do most programmers indent the conditionally executed statements in a decision structure?
? Indentation simply makes it much easier to see the structure of a program
3. What is a flag and how does it work?
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
29. What value will be stored in the variable t after each of the following statements executes?
A) T = (12> 1); ____ 1 B) T = (2 < 0); _____ 0 C) T = (5 == (3* 2));______ 0 D) T = (5 ==5); ______ 1
14. For an if statement to conditionally execute a group of statements, the statements must be enclosed in a set of ____.
Braces
28. A program will "fall through" a case section if it is missing the ___ statement.
Break
25. An expression using the conditional operator is called a(n) ____ expressioin.
Conditional
26. The expression that is tested by a switch statement must have an ____ value.
Integer
The expression following a case statement must be an ____ ____.
Integer literal or constant
20. The logical operators have ____ associativity.
Left to right
22. A variable with ___ scope is only visible when the program is executing in the block containing the variable's definition
Local or Block
17. The if/else statement is actually a form of the ____ if statement.
Nested
49. The scope of a variable is limited to the block in which it is defined.
T
50. You can use the relational operators to compare string objects.
T
51. x ! = y is the same as (x > || x < y)
T
54.
T
57
T
A conditionally executed statement should be indented one level from the if statement.
T
All lines in a block should be indented one level.
T
When an if statement is nested in the if part of another statement, the only time the inner if is executed is when the expression of the outer if is true.
T
5. Briefly describe how the && operator works.
The && operator takes two boolean expressions as operands and creates a boolean expression that is true only when both subexpressions are true. It also performs short-circuit evaluation. If the expression of the left of the && operator is false, the expression on the right side will not be checked
6. Briefly describe how the | | operator works
The || operator takes two boolean expressions as operands and creates a boolean expression that is true when either of the subexpressions is true
15. 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 _____.
True/ False
9. An expression using the greater-than, less-than, greater-than-or-equal-to, less-than-or-equal-to,equal-to, or not equal-to operator is called a(n)___expression.
relational
56
t
23. The ___ logical operator works best when testing a number to determine if it is outside a range.
||