Sams Teach Yourself C++ in 21 Days

(singke) #1
Creating Expressions and Statements 97

4


Quiz ..................................................................................................................



  1. What is an expression?

  2. Is x = 5 + 7 an expression? What is its value?

  3. What is the value of 201 / 4?

  4. What is the value of 201 % 4?

  5. If myAge,a, and bare all intvariables, what are their values after
    myAge = 39;
    a = myAge++;
    b = ++myAge;

  6. What is the value of 8+2*3?

  7. What is the difference between if(x = 3)and if(x == 3)?

  8. Do the following values evaluate true or false?
    a.^0
    b. 1
    c. –1
    d.x = 0
    e. x == 0 // assume that x has the value of 0


Exercises ..........................................................................................................



  1. Write a single ifstatement that examines two integer variables and changes the
    larger to the smaller, using only one elseclause.

  2. Examine the following program. Imagine entering three numbers, and write what
    output you expect.
    1: #include
    2: using namespace std;
    3: int main()
    4: {
    5: int a, b, c;
    6: cout << “Please enter three numbers\n”;
    7: cout << “a: “;
    8: cin >> a;
    9: cout << “\nb: “;
    10: cin >> b;
    11: cout << “\nc: “;
    12: cin >> c;
    13:
    14: if (c = (a-b))
    15: cout << “a: “ << a << “ minus b: “ << b <<
    16: _” equals c: “ << c;

Free download pdf