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.

Edited 3 Years Ago by Reverend Jim: Fixed formatting

I know we're not supposed to give homework help unless the OP shows an effort, but this does look like you've shown an effort.

These are the ones that don't look right to me:

-- 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.

This is why I think it's not right

-- 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.

(try compiling each of them, you'll see which one it is)

-- Which of the following operations has the highest precedence?
a. Postincrement.
b. Multiplication.
c. Addition.
d. Assignment.

This seems to contradict your answer.

I hope this helps you! Good luck on the test. :)

I know we're not supposed to give homework help unless the OP shows an effort, but this does look like you've shown an effort.

These are the ones that don't look right to me:

-- 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.

This is why I think it's not right

-- 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.

(try compiling each of them, you'll see which one it is)

-- Which of the following operations has the highest precedence?
a. Postincrement.
b. Multiplication.
c. Addition.
d. Assignment.

This seems to contradict your answer.

I hope this helps you! Good luck on the test. :)

helped alot thanks
looked over and these my new
-- 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 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.

for this this one, is it wrong because there are 2 ; ; after j=5
b/c when i compile it was only one that didn't work
if it isn't mind explaining?

-- Which of the following operations has the highest precedence?
a. Postincrement.
b. Multiplication.
c. Addition.
d. Assignment.

that chart very useful


how do these look?
again thanks

Edited 6 Years Ago by lgonzo: misspellings

for the second one would you mind explaining why it is not valid?

Because it wouldn't compile. hah. ;)

Um, I guess it's because there are 3 ;'s ? Also, possibly because there's no condition to end the loop.

I wouldn't think it's because there are 2 ;s in a row, because you could do this:

for ( ;; )

//but I wouldn't, because it's an endless loop (unless you have other conditions within the loop to stop it).

It's because a for is structured as for (initialize; condition; increment) So if you have for ( int i = 0; int j = 5; ; i++ ) which is the initialize, condition, and increment.

This article has been dead for over six months. Start a new discussion instead.