The Comma Operator

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.)

Listing 6.13. The postage.c Program
 // 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 ...

Get C Primer Plus, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.