You are on page 1of 16

Basics of C

Shalini Bhaskar Bajaj

Evolution of C Language
ALGOL was the first programming language
Martin Richards developed a language called BCPL(Basic Combined Programming Language)
used mainly for writing system software
Ken Thompson developed a language called 'B' based on the features of BCPL. B language was used to
create early versions of UNIX. BCPL and B are typeless languages.

Dennis Ritchie developed traditional C language at the Bell Laboratories based on the features of ALGOL,
BCPL and B together with the features of data types and some powerful features

"The C Programming Language" was published by Brain Kernighan and Dennis Ritchie after which the
language was known as "K & R C"
The American National Standards Institute(ANSI) established a committee to define a standard for C. The
committee approved the version of C in 1989 and the current version "ANSI C" evolved
ANSI C was approved by the International Standards Organization(ISO) in 1990.
Shalini Bhaskar Bajaj

Features of C Language
Efficient and Fast
Shalini Bhaskar Bajaj

Features of C Language
Simple: The language supports source code that is readable and understandable.
Efficient and Fast: C supports variety of data types, operators, built in functions and keywords
which makes the program fast and efficient.
Maintainability: The code can be readily modified to satisfy new requirements or to correct
Portability: It supports the transfer of a program from one hardware and/or software platform to
another without modification or with little modification.
Reliability: The language features support the adaptation of code of one program for use in
another application.
Robust: Rich set of built-in functions and operators used to write complex programs. C also
includes the features of low level languages like assembly language.
Structured: This feature allows the programmer to sub divide the program into sub problems
which are easier to solve.
Extendable: The C program is a collection of functions and has many builtin functions provided
by the C library. We can also add our own functions to the library.
Shalini Bhaskar Bajaj

Structure of a C Program
Documentation section

Preprocessor directives
Global declarations
Function declarations
// main function
Local variable declaration;
Statement 1;
Statement N;
Function definition

Shalini Bhaskar Bajaj

Structure of a C Program
The documentation section consists of a set of commands that gives details
about the program.
The preprocessor directives consists of #include statements to include the
header files that should be included in our program to use the built in
functions and #define statements that define the symbolic constants.
The global variables are declared next.

Shalini Bhaskar Bajaj

Structure of a C Program
The functions other than main which are called inside the main function
are declared next. (optional, if there are no user defined functions)
The main function consists of 2 parts:
local variable declarations and
the executable part which are set of instructions that perform the specific task.
The execution of the program starts from the main().

Following the main function are the definition of user defined

Shalini Bhaskar Bajaj

Sample program
//preprocessor directives
int main()
//main function
return 0;
Shalini Bhaskar Bajaj

Compiling The C Program

The C program should be converted
into machine language program for the
computer to understand.
This is done with the help of compilers
which converts the source code written
in high level language into machine

Shalini Bhaskar Bajaj

Running a C program
To run a C program, compilers are required. The actual compiler program
comes in two forms:
IDE (Integrated Development Environment)
Command-line compiler

Shalini Bhaskar Bajaj


Integrated Development Environments or IDEs
Supports the entire software development cycle
e.g. MS Visual C++, Borland, Turbo C, Code Warrior, Eclipse CDT

Provides all the capabilities for developing software


Shalini Bhaskar Bajaj


IDE- Integrated Development Environment

Shalini Bhaskar Bajaj


Command-line compiler
The command line compiler comes as a program called tcc.exe, gcc.exe, cc.exe,
g++.exe, etc. This program must be invoked from the command line, and their purpose
is to convert the C program into an executable file.
The syntax to convert .c file into .exe file is
C:\xxx:>tcc filename.c
The program has to be typed into a file separately, using an editor such as vi, emacs,
notepad, Wordpad, etc...
On Linux, compiling .c file with compiler create an executable file called a.out by
default. The executable file can be run by typing ./a.out at the terminal.

Shalini Bhaskar Bajaj


Execution of C Program
Using a Preprocessor program to convert C source code in expanded source code.
"#includes" and "#defines" statements will be processed and replaced by the
actual source codes in this step.
Using a Compiler program to convert C expanded source to assembly source code.
Using a Assembler program to convert assembly source code to object code.
Using a Linker program to convert object code to executable code. Multiple units
of object codes are linked to together in this step.
Using a Loader program to load the executable code into CPU for execution.
Shalini Bhaskar Bajaj



A. K. Sharma, Foundation of Computers & Programming in C, Dhanpat Rai publications

Yashwant Kanitkar, Let Us C, BPB Publications
E. Balagurusamy (2008), Computing Fundamentals And C Programming, Tata McGraw-Hill
P. K. Sinha, Fundamentals of Computers, BPB Publications
Yashwant Kanetkar, Solutions to Let us C
Alexis Leon and Mathews Leon (2001), Introduction to Information Technology, Tata McGraw-Hill.
Brian W. Kernighan and Dennis M. Ritchie, The C programming Language, Prentice-Hall
R.G. Dromey (2001), How to Solve it by Computer, Prentice Hall of India.
Al Kelley and Ira Pohl (1998), A Book on C Programming in C, 4th Edition, Pearson Education.
Byron Gottfried, Programming with C, Schaum's Outline
Foundation of Computing, P.K.Sinha & Priti Sinha, BPB Publications

Shalini Bhaskar Bajaj


End of Chapter

Shalini Bhaskar Bajaj