Hopefully last month’s column perked your interest in C. This month we’ll take our first look at the language.
C is a structured language similar to Pascal. Many of the same ideas and contructs are used. In C, all variables must be declared before used. The idea of functions encompasses SuperBasic’s ideas of procedures and functions.
C has FOR, WHILE, and REPEAT UNTIL loops. IF statements are treated the same as in SuperBasic. C also uses begin and end marks the same way that Pascal uses BEGIN and END. C uses { and } for this.
C is a very terse language that is not at all as easy to read as english. Where some Pascal programs can almost be read as straight english.
Let’s take a look at program 1. This is a short program that will print out the string “Hello World” on the screen.
The /* and */ mark the begin and end of comments. The include statement loads in a standard file that is used by C. Any file that ends in _h is usually a header file that includes things like constant definitions.
The heart of the program starts with main. Every C program must have a main function. The compiler starts execution with the function main.
After the begin mark ({) comes the single line of code. Printf is a C library function that prints data to the screen. C is not very powerfull and is made mostly of functions. A lot of necessary functions are in the standard C library.
At the end of the program comes the end mark. As is, this program will compile and run (I’ve tried it).
Now that you have a better grasp of the structure of C, next month we’ll try a bigger program.
/* Program 1. */
#include <stdio_h>
main()
{
printf("Hello World\n");
}