Content Frame
Note for screen reader users: There is text between the form elements on this page. To be sure that you do not miss any text, use item by item navigation methods, rather than tabbing from form element to form element.
Skip Breadcrumb Navigation
Home  arrow Student Resources  arrow Quizzes  arrow Chapter 2

Chapter 2

Flow of Control

This activity contains 10 questions.

Question 1.
What are the values of the variables x and y after executing the following code?
int x = 1, y = 0;
if (x = 0) {
   y = 1;
}
else {
   y = 2;
}

 
End of Question 1


Question 2.
Which of the following will output "Yes" if the integer variable num is either 2, 3, 4, or 5?

 
End of Question 2


Question 3.
Due to C++'s short-circuit behavior, which of the following expressions will not result in a divide by zero error?

 
End of Question 3


Question 4.
What value is stored in y after executing the following code? Note that the code has purposely not been indented, which would make the code easier to read.
int x = 0, y = 0;
x = 3;
y = 1;
if (x < 5)
if (x > 3)
y = 2;
else 
y = 3;

 
End of Question 4


Question 5.
Which of the following is incorrect regarding the behavior of the switch statements?

 
End of Question 5


Question 6.
What value is stored in x and y after the following code is executed?
int x=1, y=2;

x = (x<y) ? y*2 : y*3;

 
End of Question 6


Question 7.
Which of the following loops is equivalent to the loop below?
y=0;
do
{
   y++;
   x++;
} while (x<10);

 
End of Question 7


Question 8.
Which of the following snippets of code will force the user to repeatedly input a number until the number entered is either 1 or 2?

 
End of Question 8


Question 9.
Which snippet of code correctly adds the odd integers between 1 and 20? (including 1)

 
End of Question 9


Question 10.
Which code snippet will output a triangle of stars, as shown below?
*
**
***
****

 
End of Question 10





Pearson Copyright © 1995 - 2010 Pearson Education . All rights reserved. Pearson Addison Wesley is an imprint of Pearson .
Legal Notice | Privacy Policy | Permissions

Return to the Top of this Page