The original C language as described in; "The C
programming language", by Kernighan and Ritchie, provided 27 key words. To
those 27 the ANSI standards committee on C have added five more. This
confusingly results in two standards for the C language. However, the ANSI
standard is the dominant one.
The 32 C key words are;
auto | double | int | struct |
breakbreak | else | long | switchswitch |
case | enum | register | typedef |
char | extern | return | union |
const | float | short | unsigned |
continuecontinue | for | signed | void |
default | goto | sizeof | volatile |
do | if | static | while |
Some C compilers offer additional key words specific to the hardware
environment that they operate on. You should be aware of your own C compilers
additional key words. Most notably on the PC these are;
near, far, and huge.
C programs are written in a structured manner. A collection of
code blocks are created that call each other to comprise the complete program.
As a structured language C provides various looping and testing commands such
as;
do-while, for, while, if
and the use of jumps, while provided for, are rarely used.
A C code block is contained within a pair of curly braces
"{ }", and may be a complete procedure, in C terminology called a
"function", or a subset of code within a function. For example the
following is a code block. The statements within the curly braces are only
executed upon satisfaction of the condition that "x < 10";
if (x < 10)
{
a = 1;
b = 0;
}
while this, is a complete function code block containing a sub
code block as a do-while loop;
int GET_X()
{
int x;
do
{
printf ("\nEnter a number between 0 and 10 ");
scanf("%d",&x);
}
while(x < 0 || x > 10);
return(x);
}
Notice how every statement line is terminated in a semicolon, unless that statement marks the start of a code block, in which case it is followed by a curly brace. C is a case sensitive but free flow language, spaces between commands are ignored, and therefore the semicolon delimiter is required to mark the end of the command line.
Having a freeflow structure the following commands are
recognised as the same by the C compiler;
x = 0;
x =0;
x=0;
The general form of a C program is as follows;
compiler preprocessor statements
global data declarations
return-type main(parameter list)
{
statements
}
return-type f1(parameter list)
{
statements
}
return-type f2(parameter list)
{
statements
}
.
.
.
return-type fn(parameter list)
{
statements
}
C allows comments to be included in the program. A comment
line is defined by being enclosed within "/*" and "*/". Thus
the following is a comment;
/* This is a legitimate C comment line */
Links: Home C Programming Guide C++ programming Guide