3. INTRODUCTION
• C is one of the most popular computer languages today.
• C language has evolved from three different structured language ALGOL, BCPL and
B language.
• C was an offspring of the ‘Basic Combined Programming Language’(BCPL) called
B language, developed at Cambridge University in 1960.
• B language invented by Ken Thompson developed by Martin Richards.
• B language was modified by Dennis Ritchie at AT & T’s Bell laboratories in 1972.
• The new language was named C.
• C adopted by ‘American National Standard Institute’(ANSI).
• In 1990, a version of C language was approved by the ‘International Standard
Organisation’(ISO) and that version of C is also referred to as C89 and C99.
5. HISTORY OF C
Year Developed by
1960 International Group
1967 Martin Richard
1970 Ken Thompson
1973 Dennis Ritchie
1989 ANSI Committee
1990 ISO Committee
ALGOL
BCPL
B
Traditional C
ANSI CIS C
ANSI/ISO C
6. FEATURES OF C
• C has been written in assembly language.
• C is a high-level structured oriented programming language.
• C is a robust language with rich set of built-in function and operators.
• Programs written in C are efficient and fast.
• C is highly portable, programs once written in C can be run on another machines
with minor or no modification.
• C is basically a collection of C library functions, we can also create our own
function and add it to the C library.
• C is easily extensible.
7. BEST OF C
• One of the early programming languages.
• Still the best programming language to learn quickly.
• C language is reliable, simple and easy to use.
• C language is a structured language.
• Modern programming concepts are based on C.
• It can be compiled on a variety of computer platforms.
• Universities preferred to add C programming in their courseware.
• C program can be viewed as a group of building blocked called function.
8. APPLICATIONS
C language has widely uses, some main uses are given below.
• Used to develop software's that control embedded systems. Examples of some
embedded system are Washing machine, Microwave oven, etc.
• For creating computer applications.
• UNIX Operating System is developed in C language.
9. BASIC STRUCTURE OF C PROGRAM
More section
Documentation Section
link Section
Definition Section
Global Declaration Secation
{
Declaration Part
Executable Part
}
Subprogram Section
Function 1
Function 2 ( User – defined
. Function)
.
Function n
10. EXAMPLE
#include<studio.h> / link section /
int total=0; / Global declaration and definition section /
int sum(int,int); / Function declaration section /
int main() / main function /
{
printf(“ this is a C programn”);
total=sum(1,1);
printf(“sum of two numbers:%dn”, total);
return 0;
}
int sum(int a, int b) / User defined function /
{ / Definition section /
return a+b;
}
11. DESCRIPTION FOR EACH SECTION
Documentation Section:
we can give comment about the program, create or modified
date, author name etc.
The character or words or anything which are given between
“/*” and “*/”, won’t be considered by C compiler for compilation process.
There will be ignored by C compiler during compilation.
Link Section:
The link section consists of the header files of the functions that
are used in the program.
It provides instructions to the compiler to link functions from the
system library.
12. CONT.…
Definition Section:
All the symbolic constants are written in definition section. Macros
are know as symbolic constants.
Global Declaration Section:
The global variables that can be used anywhere in the program are
declared in global declaration section.
This section also declares the user defined functions.
FUNCTION PROTOTYPE DECLARATION SECTION:
Function prototype give many information about a function like
return type, parameter names used inside the function
13. CONT.….
main() Function section:
Every C program is started from main function and this function
contain two major sections called
Declaration Section and
Executable Section.
Declaration section declares all the variables that are used in executable part.
User Defined Function Section:
User can define their own function in this section which perform
particular task as per the user requirement.
14. EXECUTING A “C” PROGRAM
Executing a program written in C involves a series of step.
There are:
Creating the Program.
Compiling the program.
Linking the program with function that are needed from the C library.
Executing the program.
17. CONT.…
Compiler takes high level human readable program as input and
convert it into the lower level code.
This conversion takes place using different phases.
Different phases of compilers:
Analysis phase
Synthesis phase
19. LEXICAL ANALYSIS:
Task of lexical analysis is to read the input characters and produce
as output a sequence of Tokens that the parser user for syntax analysis.
Token
Source Lexical Parser
Program analyser
Get next
token
symbol
table
Lexical Analyser is First Phase of compiler.
Input to lexical analyser is “Source Code”.
20. CONT.….
Lexical analysis identifies different Lexical units in a Source code.
Different Lexical classes or Tokens or Lexemes.
Identifiers
Constants
Keywords
Operators
Lexical analyzer is also called “Linear Phase” or “Linear Analysis” or
“Scanning”.
Individual Token is also called Lexeme.
Lexical analyzer’s output is given to Syntax analysis.
21. SYNTAX ANALYSIS
• It is Second phases of compiler after Lexical Analyzer.
• It is also called as Hierarchical Analysis or Parsing.
• It Groups Tokens of source program into Grammatical Production.
• In short Syntax analysis generates Parse tree.
22. SYNTAX ANALYSIS: PARSE TREE
x = a + b;
It this statement syntax analyzer will create a parse tree from the
Tokens.
Assignment statement
=
Identifier Expression
x +
Identifier Identifier
a b
23. PARSE TREE: EXPLANATION
Syntax analyzer will check only Syntax not the meaning of
Statement.
explanation:
Addition operator plus (‘+’) operator on the two operands.
Syntax analyzer will just check whether plus operator has two
operands or not.
It does not checks the type of operands.
24. SEMANTIC ANALYSIS
Semantic analysis is the third phase of compiler.
Data type of Fist operand
Data type of Second operand
Check whether + is binary or unary
Check for number of operands supplied to operator supplied
to Operator Depending on type of operator (Unary / Binary / Ternary)
25. SOME BASIC SYNTAX RULE FOR C PROGRAM
• C is a case sensitive language so all C instruction must be written in lower case
letter.
• All C statement must be end with a semicolon.
• Whitespace is used in C describe blanks and tabs.
• Whitespace is required between keywords and identifiers.
27. PROGRAM EXPLANATION
Header File:
standard input and output (predefined)
#include<studio.h>
pre-processor directive
The pre-processor is a software program that will expand the source code while the program
is compiled.
pre-defined is used to display the results on the standard output.
Syntax:
#include<path-space>
< > angle-bracket form, pre-processor to search the directories that are specified by the
include.
28. CONT.….
main( )
This is the point where the execution begins when the program is run.
main( ) is the calling and also user-defined function.
{ } – name of parentheses (the two brackets properly called Braces).
This indication to the compiler that this is a function.
“ ” – The end result is that whatever is included between the Quotation marks
will be displayed on the monitor when the program is run.
29. CONT.….
; (semi-colon) – used as a statement Terminator.
so is required as a signal to the compiler that this line is complete.
printf (executable statement) – is the predefined, standard C function for printing
output.
n (new line character) – C compiler consider the combination of the(black lash)
and (letter n) as a one character. So it return the cursor to
the left side of the monitor and print the new line.
30. ADVANTAGES
• C is the building block for many other programming languages.
• Programs written in C are highly portable languages.
• Several standard functions are the (like in-built) that can be used to develop
programs.
• C program are basically collections of C library function, and it’s also easy to add
own function in to the C library.
• The modular structure make code debugging, maintenance and testing easier.
31. DISADVANTAGES
• C does not provide Object Oriented Programming(OOP) concepts.
• There is no runtime checking in C language.
• There is no strict type checking.
Example, we can pass on integer value.
• There is no concepts of Namespace in C.
• C does not provided binding or wrapping up of data in a single unit.
• C does not provide Constructor and Destructor.