Chapter2 Overview of c
Chapter2 Overview of c
HISTORY OF C
• The root of all modern programming language is ALGO, it is
introduced in 1960.
ALGO gave the new concept of the structure programming.
Subsequently various languages are announced.
• In 1967 Martin Richards developed a language called BCPL( Basic
Combined Programming Language) .
• In 1970, Ken Thompson created a language using many features of
BCPL and it simply called B language.
• Both BCPL and B was “type less” system programming language
• C language was developed by Dennis Ritchie at the Bell Laboratories
in 1972.
• C language uses many features of the ALGO, BCPL and B Languages. It
also added new concepts of the “data type” and many powerful
features.
• Unix operating system is totally coded in C language
• In 1983 American National Standard Institute (ANSI) appoint a
technical committee to define a standard of C.
• The committee approved a version of c in December 1989 which is
now known as ANSI C
• It was the approved by the International Standards Organization (ISO)
in 1990.This version of the c is also referred as C89
SALIENT FEATURES OF C
(IMPORTANCE OF C)
C has many advantages over other high level languages.
• It is robust.(program that performs in several way and has a very low failure
rate).
• C has the advantage of assembly level programming such as bit manipulation
and all the significant features of high level language such as easy debugging,
compactness etc. Therefore most of the C compilers are written in C.
• C is also called as a middle level language since it combines the features of high
level as well as low level programming.
• It is highly suited for writing system software and application packages.
• C consists of a rich variety of data types and powerful operators. This makes C
programs much more efficient and fast.
• It is platform independent and highly portable i.e., C can be run on
almost any operating system
• C is a structured language, where in the program is subdivided into a
number of modules. Each of these modules performs a specific task.
Further structured programming helps in making program debugging,
testing and maintenance, easier.
• One of the salient feature of C is its ability to add on to its library.
User-defined functions can be added to the C library making the
programs simpler.
• C provides manipulation of internal processor registers.
• It allows pointer arithmetic and pointer manipulation.
• pointer arithmetic: the set of valid arithmetic operations that can be
performed on pointers.
Basic structure of a C program
• The documentation section consists of a set of comment lines giving
the name of the program , the author and other details, which the
programmer would like to use later.
• The link section provides instructions to the compiler to link functions
from the system library
• The definition section defines all symbolic constants
• There are some variables that are used in more than one function,
such variables are called global variables and are declared in the
global declaration section, that is outside of all the function. This
section also declares all the user defined functions.
• Every C program must have only one main() function. It indicates that
the name of the function is main and that the program execution
should begin here.
• This section consists of 2 parts declaration part and execution part. All
the variables that are used in the program are declared in the
declaration part. There must be at least one statement in the
execution part.
• These 2 parts are enclosed between curly braces{}. Program execution
begins at the opening brace { and the closing brace } indicates the
logical end of the program
• Every statement in this Section are terminated by a semicolon(;)
• Every C program must have a main()section.
• The sub program section contains all the user defined functions that
are called in the main function.
Example:
/* Program to calculate area of a circle */ //Document section
#include<stdio.h> // Link section
#define PI 3.14159 // Definition section
main() // main()function section
{
int radius;
float area; // DECLARE VARIABLE
printf("Enter the radius of a circle ");
scanf("%d",&radius);
area=PI*radius*radius; // Executable
printf("Area of a circle=%.2f",area);
}
Rules for writing a C program:
•C program statements must be written in lower case letters. Only symbolic
constants are written in upper case letters.
• Every statement should end with a semicolon.
• Braces are used to group and mark together the beginning and end of
functions.
• Proper indentation of braces and statements make the program easier to
read and debug
• C is a case sensitive language. C is a free-form language. i.e. More than one
statement can be example: written on one line separated by a semicolon.
a=b;
x=y+1;
z=a+x;
Can be written on one line as
a=b;x=y+1;z=a+x;
Executing a C program
Executing a program written in C involves series of steps
1. Creating the program
2. Compiling the program
3. Linking the program with functions that are needed from the C
library
4. Executing the program
The source program translated into suitable execution format. The
translation is done after examining each instruction correctness. If
everything are right program translated into object code.
Linking is the process of putting together other program files and
functions that are required by the program.
Example :library function of system linked to main program .the linking
is done automatically.