Sams Teach Yourself C in 21 Days

(singke) #1

  1. See answer 2.

  2. The valid variable names are b, c, e, g, h, i, and j.
    Notice that j is correct; however, it isn’t wise to use variable names that are this
    long. (Besides, who would want to type them?) Most compilers wouldn’t look at
    this entire name. Instead, they would look only at the first 31 characters or so.
    The following are invalid:
    a. You can’t start a variable name with a number.
    d. You can’t use a pound sign (#) in a variable name.
    f. You can’t use a hyphen (-) in a variable name.


Answers for Day 4

Quiz


  1. It is an assignment statement that instructs the computer to add 5 and 8, assigning
    the result to the variable x.

  2. An expression is anything that evaluates to a numerical value.

  3. The relative precedence of the operators.

  4. After the first statement, the value of ais 10 , and the value of xis 11. After the sec-
    ond statement, both aandxhave the value 11. (The statements must be executed
    separately.)

  5. 1

  6. 19
    7.(5 + 3) * 8 / (2 + 2)

  7. 0

  8. See the section “Operator Precedence Revisited” near the end of this chapter. It
    shows the C operators and their precedence.
    a.<has higher precedence than ==does.
    b.*has higher precedence than +.does.
    c.!=and==have the same precedence, so they are evaluated left-to-right.
    d.>=has the same precedence as >. Use parentheses if you need to use more
    than one relational operator in a single statement or expression.

  9. The compound assignment operators let you combine a binary mathematical opera-
    tion with an assignment operation, thus providing a shorthand notation. The com-
    pound operators presented in this chapter are +=,-=,/=,*=, and%=.


834 Appendix F

49 448201x-APP F 8/13/02 11:22 AM Page 834

Free download pdf