Ch. 6 Flashcards

(20 cards)

1
Q

It’s possible to specify that a constant is of type decimal by appending the letter m to the constant.
True.
False.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

If a while condition is never true, the body will never execute.
True.
False.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What occurs when an empty case matches the controlling expression?
fall through
syntax error
infinite loop
None of the above.

A

fall through

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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

A

static

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

A

3 and 4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Short-circuit evaluation is a performance feature related to the evaluation of conditional AND and conditional OR expressions.
True.
False.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The break statement terminates a program.
True.
False.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Compressing statements before and in a for statement into the for header can reduce the readability of a program
True.
False.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Only one control variable may be initialized, incremented or decremented in a for statement header.
True.
False.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Modifying the control variable of a for statement in the body can cause errors.
True.
False.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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.

A

placing control statements one after another

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Unary operators (such as ++) cannot be used in conditions.
True.
False.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The for repetition statement handles the details of counter-controlled repetition.
True.
False.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

In structured programming, the only two ways to combine control statements are stacking and nesting.
True.
False.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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.

A

The condition (gender == FEMALE) is evaluated first and the evaluation stops immediately.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

A variable used as a counter should be initialized when it’s declared.
True.
False.

15
Q

The do…while repetition statement tests the condition _________ the body of the loop executes.
before
while
after
None of the above.

16
Q

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.

17
Q

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.

A

C# will implicitly convert a double to a decimal, or vice versa.

18
Q

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)

A

for (int j = 10; j >= 1; –j)