Chapter 5

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What will the following code display? int number = 0; cout << number++ << endl;​

0

What will the following code display? int number = 0; number++; --number; cout << number << endl;

0

When the following code executes what will be displayed? int num1, num2, result; for (num1 = 1, num2 = 1; num1 <= 3; num1++, num2++) { result = num1 - num2; } cout << result << endl;

0

When the following code executes, how many times will I love to code! be displayed? int number = 10; while (number < 10) { cout << "I love to code!\n"; number++; }​

0

What will the following code display? int number = 0; number++; cout << number << endl;

1

What will the following code display? int number = 0; cout << ++number << endl;

1

What will the following code display? int x = 0; if (++x == 1) cout << 1 << endl; else cout << 0 << endl; return 0;

1

What will the following code display? int number = 4; int result = 2 * ++number; cout << result << endl;

10

What will the following code display? int number = 0; number++; ++number; cout << number << endl;

2

What will the following code display? int number = 4; int result = 2 * number++; cout << result << endl;

8

In what situation should you use the for loop instead of the while or do-while loop? The loop requires an initialization. The loop uses a false test expression to stop. The loop performs an increment at the end of each iteration. All of these situations.

all of these situations

A loop that repeats a specific number of times is known as a:

count-controlled loop

Because the for loop tests its test expression after it performs an iteration, it is a posttest loop.

false

Only increment statements may be used in the update expression of a for loop.

false

The while loop is a good choice for repeating a menu.

false

This loop is specifically designed to initialize, test, and update a counter variable.

for

If a loop does not have a way of stopping, it is called:

infinite loop

When the following code executes, how many times will "Programming is awesome!" be displayed? int number = 3; while (number > 0) cout << "Programming is awesome!" << endl; number--; return 0;

infinitely

Each repetition of a loop is known as this:

iteration

This is a control structure that causes a statement or group of statements to repeat.

loop

In the following code, which variable is the counter? const int MAX_VALUE = 10; int number = 0; int result = 0; while (number < MAX_VALUE) { result = number * 2; cout << result << endl; number++; }

number

The while loop is known as this, which means it tests its expression before each iteration.

pretest loop

A counter is a variable that is regularly incremented or decremented each time a loop iterates.

true

All modifications of the for loop's counter variable should take place in the update expression, which is automatically executed at the end of each iteration.

true

An important characteristic of the while loop is that the loop will never iterate if the test expression is false to start with.

true

In general, there are two categories of loops: conditional loops and count-controlled loops.

true

In most cases, loops must contain within themselves a way to terminate.

true

It is possible for the user to determine the values that will be used in the initialization and test expressions of a for loop.

true

It is possible to execute more than one statement in the initialization expression and the update expression of a for loop.

true

The do-while loop is a posttest loop. This means it does not test its expression until it has completed an iteration.

true

The do-while loop must be terminated with a semicolon.

true

The programming style you should use with the while loop is similar to that of the if statement.

true

The while loop has two important parts: (1) an expression that is tested for a true or false value, and (2) a statement or block that is repeated as long as the expression is true.

true

When a variable is defined in the initialization expression of a for loop, the scope of the variable is limited to the loop.

true

This type of loop allows the user to decide the number of iterations.

user-controlled loop


Ensembles d'études connexes

BUS/475: Integrated Business Topics - Week 3

View Set

Bone Structure and classsification

View Set

Chap 12 Smart book Human Resource

View Set

Lab Quiz 3 - Mammalogy 459 w/ Rentz

View Set

Chapter 5, Chapter 6, Chapter 7, Chapter 8

View Set

Chapter 21: The Renaissance in Quattrocento Italy

View Set

Steroidal Antiinflammatory Drugs EDAPT

View Set

BYU BIOL-043-S002 Biology Quizzes

View Set

India quiz nationals🐰🙏(1.5)

View Set

Entrainements hybrides "Fonction start-stop"

View Set

AC456 Chapter 6: Accounting for General Long-Term Debt and Debt Service

View Set

Antebellum America and American Sectionalism

View Set