O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required