Chapter 4 Quiz Starting Out With C++ 013

Let's analyze the following statement assuming that y is 6.

if ( y = 7 )
   cout << " y is 7.  How lucky of you. ";
else
  cout << "y is not 7.  Sorry about that.";

What will be the result of this section of code.

a.  cout << "y is not 7.  Sorry about that.";
b. cout << " y is 7.  How lucky of you. "; //will always execute regardless of the value of y
c. y=7 is an assignment and not a comparison will not compile
d. I was texting in class and have no absolutely no idea.
e. This will compile but completely skip both statements.

Chapter 4 Quiz Starting Out With C++ 012

Putting a semicolon after the if (expression) is a common mistake and will lead to a compiler error

if (x>y);
  temp++;

a. false
b. today's compilers are smart enough and will remove the semi-colon
c. you'll get a warning message but the compiler knows what you mean
d. true

Chapter 4 Quiz Starting Out With C++ 011

In C++, you can only have one statement following a relational test?

a. true
b. false

Chapter 4 Quiz Starting Out With C++ 010

if (expression)
  statement;
else
  statement;

Does the above work in C++?

a. true
b. false

Chapter 4 Quiz Starting Out With C++ 009

How do you write an "if" statement in C++?  Which sample below is the best

a.
  if (x >y) then
{
   tmp++;
}

b.
if ( x >y )
 tmp++;

c.
 if x>y
  tmp++
else
 tmp--;

d.
None of the above.  They won't compile

Chapter 4 Quiz Starting Out With C++ 008

What is the value of the relation expression below, given that x is 5 and y is 1.  z is a bool.

z = x < y;

a. true
b. false
c. 1
d. 0
e. None of the above, you can't assign result of expression, only test it