You are on page 1of 6

C Programming - An Overview

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 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.


Basic structure of C programs
.
.....Documentation Section
.....
.....Link Section
.....
.....Definition Section
.....
.....Global declaration Section
.....
.....main() function section
.....{
..........Declaration Section
.....
..........Executable Section
.....}

.....Sub-program Section

.....function1
.....{
..........Statements
.....}

.....function2
.....{
..........Statements
.....}

.....function3
.....{
..........Statements
.....}

.
The documentation section consists of a set of comment lines giving the name of
the program, the author and other details such as a short description of the purpose of the
program.

The link section provides instructions to the compiler to link functions from the
system library.

The definition section defines all the symbolic constants. The variables can be
declared inside the main function or before the main function.

Declaring the variables before the main function makes the variables accessible to all the
functions in a C language program, such variables are called Global Variables.

Declaring the variables within main function makes the usage of the variables confined to
the main function only and it is not accessible outside the main function.

Every C program must have one main function. Enclosed in the main
function is the declaration and executable parts.

In the declaration part we have all the variables.

There is atleast one statement in the executable part.

The two parts must appear between the opening and closing braces
The sub-program section contains all the user-defined functions that
are called in the main function.

User-defined functions are generally placed immediately after the main


function although they may appear in any order.

You might also like