6. INTRODUCTION TO C LANGUAGE
What is C ?
C is Programming Language
C is a General Purpose Programming language
C is a Procedure Oriented Language
C is a Structured Language
C is a Middle Level Language
C is a Superset Language of all the Programming
Language
7. HISTORY OF C LANGUAGE
ALGOL 60
(BY AN INTERNATIONAL COMMITTEE, 1960) IT WAS TOO ABSTRACT &
TOO GENERAL
CPL
(BY CAMBRIDGE & LONDON UNIVERSITY,
1963)
DROWBACKS/SHORTCOMMINGS
BCPL
HARD TO LEARN & DIFFICULT
TO IMPLEMENT
B
(MARTIN RICHARDS AT
CAMBRIDGEUNIVERSITY, 1967 )
(KEN THOMSON AT BELL LABS, 1970)
TOO LESS POWERFULL &
TOO LESS SPECIFIC
MACHINE DEPENDENT &
TYPELESS
C
(DENNIS RITCHE AT BELL LABS, 1972
8. IMPORTANCE OF C LANGUAGE
FLEXIBILITY
POWERFULL
SMALL SIZE
MODULAR DESIGN
PORTABILITY
HIGH LEVEL STRUCTURED LANGUAGE FEATURES
LOW LEVEL FEATURES
USE OF POINTERS
EASY TO LEARN
EASY TO DEBUG
EFFICIENCY ( EASY TO EXECUTE )
EASY TO USE
RELIABLE
9. CREATING A SOURCE CODE
COMPILING THE SOURCE CODE
LINKING THE SOURCE CODE
RUNNING THE EXECUTABLE CODE
WRITING & EXECUTING A C PROGRAM
EDITOR
WRITTEN C PROGRAM
PRE
PROCESSOR
COMPILER
PRE-PROSSED CODE
COMPILATION
OBJECT
CODE
LINKER
EXECUTABLE
CODE
Linking
.OBJ
FILE
.EXE
FILE
10. START
TYPE THE PROGRAM
COMPILER SOURCE CODE
SYNTAX
ERROR
LINK THE PROGRAM
EXECUTE
LOGICAL
ERROR
STOP
WRITTEN
C CODE
EDIT PROGRAMME
LIBRARY +
OBJECT
PROGRAMME
CORRECT
I/O
DATA
SOURCE
PROGRAMME FILE.C
OBJECT
PROGRAMME
NO
NO
YES
FILE.OBJ
EXECUTABLE
CODE
FILE.EXE
Fig: Flowchart of execution of c
programme
11. STRUCTURE OF C PROGRAMME
DOCUMENTATION SECTION1
LINK SECTION
DEFINATION SECTION
GLOBAL DECLARATION
SECTION
MAIN () SECTION
2
3
4
5
OPTIONAL
COMPULSORY
OPTIONAL
OPTIONAL
COMPULSORY
{
Declarative part
Executable part
}
14. Fundamental Data Types
Data Types Description Size ( In Bytes ) Range
Int An integer number 2 bytes -32768 to 32767
Float A single precision
floating point number
4 bytes -2147483648 to
2147483647
Char A single character 1 byte -128 to 127
Double A double precision
floating point number
8 byte 1.7 e-308 to 1.7 e+308
Void Empty data type 0 Valueless
16. 1. Null Statement ; on line
2. Expression Statement assignment/function call
3. Compound Statement { }
4. Selection Statement condition check if if else
5. Iteration Statement Iteration while do while for
6. Jump Statement go to break continue
7. Labeled Statement xx
STATEMENT
Def: Computer can take the decision but taking a decision for computer statement is
required.
19. 1. While Loop
Entry controlled loop / top tested loop
Syntax :
Initialization;
While ( Test_condition)
{
Body of the while loop;
}
20. 2. Do….while Loop
Exit controlled loop / bottom tested loop
Syntax :
Initialization;
Do
{
Body of the do loop;
}
While (Test_condition);
21. 3. For Loop
Most powerful, flexible & commonly used Loop
Top tested
Syntax :
For(initialization; test_condition; incr/decr)
{
Body of the for loop
}
22. Jumping statement
Break statement : whole program terminated
Continue statement : that particular stat is terminated
Goto statement
23. Array
Definition: Array is the collection of similar type of data elements.
Types of Array
1. One dimensional array
2. Two dimensional array / matrix
3. Multi dimensional array
More than one values can be stored in a variable of a similar type.
24. Array declaration does following things:
The name of the array
The type of the array
The dimension of the array
The size of the array
For ex:
int a[10];
int a[2] [2];
int a[2] [3] [3];
25. Handling of C character set
Reading & writing string
Combining string together - strcat
Copying one string to another – strcpy
Comparing string for equality – strcmp
Calculating length of string – strlen
Def : A string is an array of characters terminated by a special character Null
(‘0’)
29. 4.Calculating the length of string :
Void main()
{
Int I;
Char city[]= “Osmanabad”;
i=strlen(city);
Printf(“%d”,strlen(city));
}
Output:
9
30. Def: A structure is a collection of different
types of data types grouped together under
a single name. Each variable within the
structure is called a member. The name
given to the structure is called structure
tag.
31. Syntax :
Struct tag
{
Member1;
Member2;
.
.
Membern;
};
Struct tag instance;
For Ex:
Struct student
{
Char name[20];
Int roll no;
Int marks;
};
Struct student s;
Instance is the structure variable used to initialize the structure
32. Def: A UNION is a collection of different
types of data types grouped together under
a single name. Each variable within the
union is called a member. The name given
to the union is called union tag.
33. Syntax :
union tag
{
Member1;
Member2;
.
.
Membern;
};
union tag instance;
For Ex:
union student
{
Char name[20];
Int roll no;
Int marks;
};
unioin student s;
Instance is the structure variable used to initialize the structure
34. Pointer
Pointer is an important part of the c language which
provide a powerful flexible way to manipulate the data.
Reason for using the pointer:
1. accessing the variable defined outside of the
function.
2. more efficient in handling data tables.
3. reduce the length of the program
4. reduce the complexity
5. pointer increase the execution speed.
Def: Pointer is the variable which store the address of the
next variable.
35. FUNCTION
A function is named- accessed by name
A function is independent-perform the task on its
own
Specific task
It will return the value to the calling program.
Def : A function is a self-contained block of statement
that perform a specific well defined task and may
return the value to the calling program.