September 2001
Beginner
970 pages
23h 20m
English
The comma operator extends the flexibility of the for loop by enabling you to include more than one initialization or update expression in a single for loop specification. For example, Listing 6.13 shows a program that prints first-class postage rates. (At the time of this writing, the rate is 34 cents for the first ounce and 23 cents for each additional ounce. You can check www.usps.gov for the current rates.)
// postage.c -- first-class postage rates #include <stdio.h> int main(void) { const int FIRST_OZ = 34; const int NEXT_OZ = 23; int ounces, cost; printf(" ounces cost\n"); for(ounces=1, cost=FIRST_OZ; ounces <= 16; ounces++, cost += NEXT_OZ) printf("%5d %7d\n", ounces, cost); return ... |
Read now
Unlock full access