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