Tuesday, October 27, 2009

C Programming

C Language

Developed originally at Bell Labs by Ken Thompson and Dennis Ritchie in the second half of the 1980’s, the C Language has become a high-level programming language responsible for almost all operating systems of today. Together with the object-oriented successor of C, C++, these two languages have become commercial software’s first choice in programming language. UNIX runs on C Language and is becoming commercially acceptable on a mass scale.

Venture capital seems to be financing C Language-based software development as it is gaining interest in the job market and receiving support from large corporations and big business markets. Communications and Information Technology are some of the employment opportunities available for the expert C Language programmer.

Like any language learning exercise, the C Language begins with Variables and Constants. These Variables and Constants of basic data types create words and sentences of C, forming the C programming language. A set of instructions and rules for writing in the C Language exists, as is part of any computer programming language. These instructions are explained in online tutorials defining Statements, Expressions, Operators, Managing Input/Output Operations, Strings, Arrays, Functions, Pointers, Dynamic Memory allocation and more.

Using Preprocessor directives, Macros, define identifier string, Simple macro substitution, Macros as arguments, Nesting of macros, Un-defining a macro and File inclusion, the C Language programmer becomes familiar with the terms and functions of this complex programming language. The preprocessor in the C Language is examined in tutorials that describe modifying and reading C Language and discuss efficiency and portability.

C Programming Language - An Overview

In this tutorial you will learn about C Programming Lanuage, Overview of C, Sample program - Printing a message, Executing a C Program and Basic structure of C programs.

Overview of C

C is a programming language. It is most popular computer language today because it is a structured high level, machine independent language. Programmers need not worry about the hardware platform where they will be implemented.

Dennis Ritchie invented C language. Ken Thompson created a language which was based upon a language known as BCPL and it was called as B. B language was created in 1970, basically for unix operating system Dennis Ritchie used ALGOL, BCPL and B as the basic reference language from which he created C.

C has many qualities which any programmer may desire. It contains the capability of assembly language with the features of high level language which can be used for creating software packages, system software etc. It supports the programmer with a rich set of built-in functions and operators. C is highly portable. C programs written on one computer can run on other computer without making any changes in the program. Structured programming concept is well supported in C, this helps in dividing the programs into function modules or code blocks.

Sample program-1
Printing a message
Consider the following message

#include
main()
{
...../* Printing begins here */
.....printf (“C is a very good programming language.”);
...../* Printing ends here */
}

The first line is a preprocessor command which adds the stdio header file into our program. Actually stdio stands for standard input out, this header file supports the input-output functions in a program.

In a program, we need to provide input data and display processed data on standard output – Screen. The stdio.h header file supports these two activities. There are many header files which will be discussed in future.

The second line main() tell the compiler that it is the starting point of the program, every program should essentially have the main function only once in the program. The opening and closing braces indicates the beginning and ending of the program. All the statements between these two braces form the function body. These statements are actually the C code which tells the computer to do something. Each statement is a instruction for the computer to perform specific task.

The /* .... */ is a comment and will not be executed, the compiler simply ignores this statement. These are essential since it enhances the readability and understandability of the program. It is a very good practice to include comments in all the programs to make the users understand what is being done in the program.

The next statement printf() statement is the only executable line in the above sample program. The printf() function is a standard inbuild function for printing a given line which appears inside the double quotes. Therefore in the standard output device we can see the following line

C is a very good programming language.

The next line is again a comment statement as explained earlier. The closing brace indicates the end of the program.

Executing a C Program

The following basic steps is carried out in executing a C Program.

1. Type the C lanuage program.

2. Store the program by giving a suitable name and following it with an extension .c

3. Compile the program

4. Debug the errors if any, that is displayed during compile.

5. Run the program.

No comments:

Post a Comment