Ch. 6 Flashcards
(20 cards)
It’s possible to specify that a constant is of type decimal by appending the letter m to the constant.
True.
False.
True
If a while condition is never true, the body will never execute.
True.
False.
True
What occurs when an empty case matches the controlling expression?
fall through
syntax error
infinite loop
None of the above.
fall through
Many classes provide methods to perform common tasks that do not require specific objects-they must be called using a class name. Such methods are called ________ methods.
classwide
dot (.)
console
static
static
Which of the following for-loop control headers results in equivalent numbers of iterations:
1: for (int q = 1; q <= 100; ++q)
2: for (int q = 100; q >= 0; –q)
3: for (int q = 99; q > 0; q -= 9)
4: for (int q = 990; q > 0; q -= 90)
1 and 2
3 and 4
1 and 2 have equivalent iterations and 3 and 4 have equivalent iterations
None of the loops have equivalent iterations
3 and 4
Short-circuit evaluation is a performance feature related to the evaluation of conditional AND and conditional OR expressions.
True.
False.
True
The break statement terminates a program.
True.
False.
False
Compressing statements before and in a for statement into the for header can reduce the readability of a program
True.
False.
True
Only one control variable may be initialized, incremented or decremented in a for statement header.
True.
False.
False
Modifying the control variable of a for statement in the body can cause errors.
True.
False.
True
Control-statement stacking is the process of:
placing control statements within each other
placing control statements one after another
reducing the number of statements required by combining statements
None of the above.
placing control statements one after another
Unary operators (such as ++) cannot be used in conditions.
True.
False.
False
The for repetition statement handles the details of counter-controlled repetition.
True.
False.
True
In structured programming, the only two ways to combine control statements are stacking and nesting.
True.
False.
True
Suppose variable gender is MALE and age equals 60, how is the expression (gender == FEMALE) && (age >= 65) evaluated?
The condition (gender == FEMALE) is evaluated first and the evaluation stops immediately.
The condition (age >= 65) is evaluated first and the evaluation stops immediately.
Both conditions are evaluated, from left to right.
Both conditions are evaluated, from right to left.
The condition (gender == FEMALE) is evaluated first and the evaluation stops immediately.
A variable used as a counter should be initialized when it’s declared.
True.
False.
True
The do…while repetition statement tests the condition _________ the body of the loop executes.
before
while
after
None of the above.
after
Counting loops should be controlled with whatever data type most closely reflects the operations taking place, whether that is an int, float or double.
True.
False.
False
Which of the following statements is false?
C# does not include an exponentiation operator.
The expression Math.Pow(x, y) calculates the value of x raised to the yth power.
C# will implicitly convert a double to a decimal, or vice versa.
In loops, avoid calculations for which the result never changes-such calculations should typically be placed before the loop. Optimizing compilers will typically do this for you.
C# will implicitly convert a double to a decimal, or vice versa.
Which of the following will count down from 10 to 1 correctly?
for (int j = 10; j <= 1; ++j)
for (int j = 1; j <= 10; ++j)
for (int j = 10; j > 1; –j)
for (int j = 10; j >= 1; –j)
for (int j = 10; j >= 1; –j)