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

Listing 6.11 The postage.c program.
/* 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 ...

Get C Primer Plus®, Third 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.