Sams Teach Yourself C in 21 Days

(singke) #1
Quiz ................................................................................................................


  1. What is the following C statement called, and what is its meaning?
    x = 5 + 8;

  2. What is an expression?

  3. In an expression that contains multiple operators, what determines the order in
    which operations are performed?

  4. If the variable xhas the value 10 , what are the values of xandaafter each of the
    following statements is executed separately?
    a = x++;
    a = ++x;

  5. To what value does the expression 10 % 3evaluate?

  6. To what value does the expression 5 + 3 * 8 / 2 + 2evaluate?

  7. Rewrite the expression in question 6, adding parentheses so that it evaluates to 16.

  8. If an expression evaluates to false, what value does the expression have?

  9. In the following list, which has higher precedence?
    a.==or<
    b.*or+
    c.!=or==
    d.>=or>

  10. What are the compound assignment operators, and how are they useful?


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


  1. The following code is not well-written. Enter and compile it to see whether it
    works.
    #include <stdio.h>
    int x,y;int main(){ printf(
    “\nEnter two numbers”);scanf(
    “%d %d”,&x,&y);printf(
    “\n\n%d is bigger”,(x>y)?x:y);return 0;}

  2. Rewrite the code in exercise 1 to be more readable.

  3. Change Listing 4.1 to count upward instead of downward.

  4. Write an ifstatement that assigns the value of xto the variable yonly if xis
    between 1 and 20. Leave yunchanged if xis not in that range.

  5. Use the conditional operator to perform the same task as in exercise 4.


90 Day 4

07 448201x-CH04 8/13/02 11:15 AM Page 90

Free download pdf