been doing reiew questions to prepare for a c++ test,
and was hoping someone could help me out by looking over the ansewers i have so far. what i have is in red.
thank you very much :)
-- Which of the following operations has the highest precedence?
a. Postincrement.
b. Multiplication.
c. Addition.
d. Assignment.
-- Which of the following does counter-controlled repetition require?
a. An initial value.
b. A condition that tests for the final value.
c. An increment or decrement by which the control variable is modified each time through the loop.
ANS d. All of the above.
--. If a variable is declared in the initialization expression of a for structure, then:
a. It is automatically reinitialized to zero once the loop is finished.
b. The scope of the variable is restricted to that particular for loop.
c. It retains its final value after the loop is finished.
d. It can not be used in any structures that are nested in that for structure.
-- Which of the following is not true?
a. The three expressions in the for structure are optional.
b. The initialization and increment expressions can be comma-separated lists.
c. You must declare the control variable outside of the for loop.
d. A for loop can always be used to replace a while loop, and vice versa.
--. Consider the execution of the following for loop
for (int x = 1; x < 5; increment )
cout << x + 1 << endl;
If the last value printed is 5, which of the following might have been used for increment?
a. x++.
b. x += 1.
c. ++x.
d. Any of the above.
-- Which of the following for headers is not valid?
a. for ( int i = 0; i < 10; i++ ).
b. int i = 0;
for ( ; i < 10; i++ ).
c. for ( int i = 0; int j = 5; ; i++ ).
d. All of the above.
-- float and double variables should be used:
a. To perform monetary calculations.
b. As counters.
c. To store true/false values.
d. As imprecise representations of decimal numbers.
-- Which of the following is a parameterized stream manipulator used to format output?
a. setw.
b. right.
c. left.
d. fixed.
-- If a do…while structure is used:
a. An infinite loop cannot take place.
b. Counter-controlled repetition is not possible.
c. The body of the loop will execute at least once.
d. An off-by-one error cannot occur.
-- What will the following program segment do?
int counter = 1;
do
{
cout << counter << " ";
} while ( ++counter <= 10 );
a. Print the numbers 1 through 11.
b. Print the numbers 1 through 10.
c. Print the numbers 1 through 9.
d. Cause a syntax error.
-- A switch statement should be used:
a. As a single-selection structure.
b. As a double-selection structure.
c. As a multiple-selection structure.
d. To replace all if…else statements.
-- Which of the following is correct when labeling cases in a switch structure?
a. case1.
b. Case1.
c. case 1.
d. Case 1.
--. switch can be used to test:
a. int constants.
b. float constants.
c. string constants.
d. all types of constants.
-- Which of the following data types can be used to represent integers?
a. char.
b. long.
c. hort.
d. All of the above.