Taking Another Step

The first sample program was easy, and the next example, shown inListing 2.2, isn't much harder.

Listing 2.2 The fathm_ft.c program.
/* fathm_ft.c -- converts 2 fathoms to feet */
#include <stdio.h>
int main (void)
{
   int feet, fathoms;
   fathoms = 2;
   feet = 6 * fathoms;
   printf("There are %d feet in %d fathoms!\n", feet, fathoms);
   return 0;
}

What's new? We supplied a program description, declared multiple variables, did some multiplication, and printed the values of two variables. Let's examine these points in more detail.

Documentation

First, the program begins with a comment identifying the filename and the purpose of the program. This kind of program documentation takes but a moment to do and is helpful later on when you ...

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.