Characterists of the C Language
- All C programs consist of a set of one or more functions.
All executable code in C resides within these functions.
- All C functions are created equal. That is to say any function
can call any other function (including itself) in a C program.
- Every program in C must have one functions named main().
The only difference between main() and other functions is that program
execution begins and ends in main(). Therefore main() is
considered the "driver" of a C program.
- All C functions consist of a function header and a function
body consisting of a block of code.
int main(void)
{
statements;
}
- Any time you have zero or more C statements enclosed with braces { }
this is called a block. There are function blocks but there can also be
blocks within other blocks. All you need is braces!
- A C statement consists of a set of expressions terminated
with a semicolon ( ; ).
c = 2 * PI * r;
- Functions communicate (pass data) to each other using calling parameters
and return values. The calling function passes data to the called function
by passing parameters. The called function can pass data back in its
return value.
- The function header lists the parameters which must be passed
to the function within parenthesis ( ). This list, which includes
the data types as well as the local identifiers of the
parameters, is called the argument list. The arguments in this
list are called the formal arguments for the function.
int a_function(int i, int j)
{
int a;
a = a_function(i,j);
return a;
}
- In the above function a_function() accepts two integer values
from the calling function (identified within the function as i
and j) and returns an integer value. Note that a_function()
calls a_function(). It is legal in C for a function to
call itself. This is called recursion.
- Comments can be placed within your C code using the
/* to open a comment block and */ to close a comment block.
Comments can be on more than one line as long as they are between the
/* and */. The compiler ignores anything in between:
/* This is a comment in C */
/*
So is this
*/
- An identifier is a name of a variable or function in
a C program. It is a sequence of letters and digits but
must begin with a letter. The underscore (_) is a letter
which can be used in identifiers. Identifiers are case sensitive.
That is, upper and lower case letters are different. Thus
AverageCost and Averagecost are two different
identifiers! Here are some more examples of C identifiers:
b3 c10x NEWNAME
THIS_ID NewName
- Identifiers can be any length but to most C compilers only
the first 32 characters are significant. So your identifiers
must be unique within the first 32 characters.
- Certain words have special meaning to the compiler. These words
are known as reserved or keywords. You cannot use keywords
as identifiers. Keywords must be in lower case. Here is a list
of keywords in C:
| auto | double | if | static | while |
| break | else | int | struct |
| case | enum | long | switch |
| char | extern | register | typedef |
| continue | float | return | union |
| default | for | short | unsigned |
| do | goto | sizeof | void |
- All symbols used in C are referred to as punctuation. The newline,
blank (space), and tab characters are referred to as whitespace.