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

Taking Another Step

The first sample program was pretty easy, and the next example, shown in Listing 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);
   printf("Yes, I said %d feet!\n", 6 * fathoms);

   return 0;
}

What's new? The code provides a program description, declares multiple variables, does some multiplication, and prints the values of two variables. Let's examine these points in more detail.

Documentation

First, the program begins with a comment (using the new comment style) identifying the filename and the purpose of the program. This ...

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