The C Programming Language |
Article Rating: Poor
(# of votes: 1) |
|
| Author:
| PrincesSoha
|
|
| Submitted: |
01-Jan-1970 01:00:00 |
| Imported From: |
zZine (original author: PrincesSoha)
|
| The C Programming language was written by Dennis Ritchie of Bell Laboratories. The first C compiler ran on a DEC PDP-11 computer under Unix, and later versions of Unix were written almost entirely in C!
|
|
C is based on the languages BCPL and B, hence the name C. B was written in 1970 by Ken Thompson for the first version of Unix, which ran on the PDP-7 computer. Many of the characteristics of B and BCPL are found in C, but C differs from these two languages in one very important respect.
BCPL and B are typeless languages, the only data type is the machine word. This data type is used directly or indirectly (via special operators) to store all the data used in any program. However, C has several ?built-in? data types (e.g. char, int, float, double) and any number of derived data types (arrays, structures, etc.).
In 1978, Ritchie and Brian Kernighan published the first edition of The C Programming Language. This book, known to C programmers as "K&R", served for many years as an informal specification for the language. The version of C that it describes is commonly referred to as "K&R C." (The second edition of the book covers the later ANSI C standard, described below.)
C is a "medium level? language, in that C has only a few operators which act on collections of data such as arrays, strings and sets. The C languages also cannot communicate with the outside world - there are no input or output routines. These operations are provided by a collection of standard library functions which are available via the compiler. However, it has the same sort of control capabilities found in higher level languages.
As mentioned above, the first C compiler was written for the Unix operating system. The language was then used to write many other Unix utilities. The next logical step, then, was to write the next version of Unix in C. This set the trend in operating system development. Being able to write an operating system in a low level language has obvious benefits in terms of development time, bug detection and correction, and maintenance of the software. All versions of Unix since the development of C have been written in C, and most versions of MS-DOS were also written in C.
Programmers writing systems programs in C have the entire computer under their control. There is not one part of the computer memory they cannot access. All the bit manipulation routines are available. Control over memory organization can easily be achieved. And yet they are writing in a higher level language with all the benefits they bring, like type checking, loops, branching, variables, arrays, etc. Goodbye assembler, hello C!
Why use C? C (and its object-oriented version, C++) is one of the most widely used third generation programming languages. Its power and flexibility ensure it is still the leading choice for almost all areas of application, especially in the software development environment.
Many applications are written in C or C++, including the compilers for other programming languages. Many operating systems are written in C. It continues to adapt to new uses, the latest being Java, which is used for programming Internet applications. C has many strengths - it is flexible and portable, it can produce fast, compact code, it provides the programmer with objects to create and manipulate complex structures (e.g classes in C++) and low level routines to control hardware (e.g input and output ports and operating system interrupts). It is also one of the few languages to have an international standard, ANSI C.
C is almost certainly available on more machines then any other programming language. The fact that C is used to provide the operating system and system tools for most new computers means, ipso facto, that a C compiler for that machine has been developed (actually it doesn't ? but it usually does).
Criticisms of C: It overuses operators, allows misuse of types, can be difficult to read, and can be good at (temporarily) killing PCs!
Here is an example of a C Program
/* This program prints a one-line message */
#include <stdio.h>
int main()
{
printf("Hello World\\n");
return 0;
}
- The symbols /* and */ delimit a comment. Comments are ignored by the compiler, and are used to provide useful information for humans that will read the program.
- main() C programs consist of one or more functions. One and only one of these functions must be called main.
- The brackets following the word main indicate that it is a function and
not a variable.
- { } braces surround the body of the function, which consists of one or more instructions.
- printf() is a library function that is used to print on the standard output stream (usually the screen).
- "Hello World\\n" is a string constant.
\\n is the newline character.
; a semicolon terminates a statement.
return 0; return the value zero to the operating system.
C is case sensitive, so the names of the functions ( main and printf ) must be typed in lower case as above.
With a few exceptions, any amount of white space (spaces, tabs and newlines) can be used to make your programs more readable. There are many conventions for program layout, just choose one that suits you, or alternatively get a program to format your code for you.
This article was originally published by CyberArmy.net in the CyberArmy Library.
|
|
You must be logged in to vote on an article
|
About Us | Privacy Policy | Mission Statement | Help
|