Quiz ................................................................................................................
- What is the following C statement called, and what is its meaning?
x = 5 + 8; - What is an expression?
- In an expression that contains multiple operators, what determines the order in
which operations are performed? - 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; - To what value does the expression 10 % 3evaluate?
- To what value does the expression 5 + 3 * 8 / 2 + 2evaluate?
- Rewrite the expression in question 6, adding parentheses so that it evaluates to 16.
- If an expression evaluates to false, what value does the expression have?
- In the following list, which has higher precedence?
a.==or<
b.*or+
c.!=or==
d.>=or> - What are the compound assignment operators, and how are they useful?
Exercises ..........................................................................................................
- 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;} - Rewrite the code in exercise 1 to be more readable.
- Change Listing 4.1 to count upward instead of downward.
- 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. - 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