Sams Teach Yourself C in 21 Days

(singke) #1
6:
7: int main( void )
8: {
9: /* Set a and b both equal to 5 */
10:
11: a = b = 5;
12:
13: /* Print them, decrementing each time. */
14: /* Use prefix mode for b, postfix mode for a */
15:
16: printf(“\nPost Pre”);
17: printf(“\n%d %d”, a--, --b);
18: printf(“\n%d %d”, a--, --b);
19: printf(“\n%d %d”, a--, --b);
20: printf(“\n%d %d”, a--, --b);
21: printf(“\n%d %d\n”, a--, --b);
22:
23: return 0;
24: }

Post Pre
5 4
4 3
3 2
2 1
1 0
This program declares two variables,aandb, in line 5. In line 11, the variables
are set to the value of 5. With the execution of each printf()statement (lines 17
through 21), both aandbare decremented by 1. After ais printed, it is decremented,
whereasbis decremented before it is printed.

66 Day 4

LISTING4.1 continued

OUTPUT

ANALYSIS

On Day 2, “The Components of a C Program,” you learned about another
unary operator, sizeof. While you might be inclined to think that operators
should look like symbols, the sizeofkeyword is actually considered an oper-
ator.

Note


The Binary Mathematical Operators
C’s binary operators take two operands. The binary operators, which include the common
mathematical operations found on a calculator, are listed in Table 4.2.

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

Free download pdf