Sams Teach Yourself C++ in 21 Days

(singke) #1

  1. The answers are
    a. False
    b. True
    c. True
    d. False
    e. True


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


  1. The following is one possible answer:
    if (x > y)
    x = y;
    else // y > x || y == x
    y = x;

  2. See exercise 3.

  3. Entering 20 , 10 , 50 gives back a: 20,b: 30,c: 10.
    Line 14 is assigning, not testing for equality.

  4. See Exercise 5.

  5. Because line 6 is assigning the value of a-bto c, the value of the assignment is a
    (2) minus b(2), or 0. Because 0 is evaluated as false, the iffails and nothing is
    printed.


Day 5....................................................................................................................


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


  1. The function prototype declares the function; the definition defines it. The proto-
    type ends with a semicolon; the definition need not. The declaration can include
    the keyword inlineand default values for the parameters; the definition cannot.
    The declaration need not include names for the parameters; the definition must.

  2. No. All parameters are identified by position, not name.

  3. Declare the function to return void.

  4. Any function that does not explicitly declare a return type returns int. You should
    always declare the return type as a matter of good programming practice.

  5. A local variable is a variable passed into or declared within a block, typically a
    function. It is visible only within the block.


826 Appendix D

32 0672327112_app_d.qxd 11/19/04 12:30 PM Page 826

Free download pdf