September 1998
Intermediate to advanced
848 pages
20h 13m
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.11 shows a program that prints first-class postage rates. (At the time of this writing, the rate is 32 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>
#define FIRST 32
#define NEXT 23
int main(void)
{
int ounces, cost;
printf(" ounces cost\n");
for(ounces=1, cost=FIRST; ounces<= 16; ounces++,
cost += NEXT)
printf("%5d %7d\n", ounces, cost);
return 0;
}
|
The first ...
Read now
Unlock full access