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

A Simple Sample of C

Let's take a look at a simple C program. This program, shown in Listing 2.1, serves to point out some of the basic features of programming in C. Before you read the upcoming line-by-line explanation of the program, read through Listing 2.1 to see if you can figure out for yourself what it will do.

Listing 2.1. A Simple C Program
#include <stdio.h>
int main(void)               /* a simple program             */
{
   int num;                  /* define a variable called num */
   num = 1;                  /* assign a value to num        */

   printf("I am a simple "); /* use the printf() function    */
   printf("computer.\n");
   printf("My favorite number is %d because it is first.\n",num);
   return 0;
}

If you think this program will print some things on your screen, you're right! Exactly what will be printed ...

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