Introduction to Turbo C
P
Programming
i Environment
E i
t
Chapter No 1
Compiled By:
Sir Syed University of Engineering & Technology
Computer Engineering Department
University Road, Karachi-75300, PAKISTAN
Course Instructors
Engr. Tauseef Mubeen
tmubeen@ssuet.edu.pk
CPPS - Chapter No 1
Course Books
Text Book:
Turbo C Programming For The PC ( Revised Edition )
By Robert Lafore
Reference Books:
1.
Let Us C
By Yashavant Kanetkar
2.
CPPS - Chapter No 1
Contents
Computer Language
Types of Computer Languages
Processing a High Level Language Program
Introduction to C Language
Why use C Language?
Turbo C Development System
Files used in C Program Development
Writing a Program in C Language
Saving the Program in C Language
The Basic Structure of C Program
CPPS - Chapter No 1
Computer Language
A computer language is a set of rules and
conventions used to convey the information to a
computer
CPPS - Chapter No 1
CPPS - Chapter No 1
CPPS - Chapter No 1
CPPS - Chapter No 1
CPPS - Chapter No 1
10
CPPS - Chapter No 1
11
CPPS - Chapter No 1
CPPS - Chapter No 1
13
CPPS - Chapter No 1
14
CPPS - Chapter No 1
P r o c e s s in g
H ig h
L e v e l L a n g u a g e
p ro g ra m
Y o u e n te r th e p ro g ra m
a n d s a v e it a s a
S o u r c e F ile
S o u rc e
F ile
R e v is e d
S o u rc e
F ile
T h e C o m p ile r a tt e m p ts t o
t r a n s la t e t h e p r o g r a m
Y o u c o rre c t
S y n ta x E rro rs
S u c c e s s
O b je c t
F ile
F a ilu r e
L is t o f
E rro rs
T h e L in k e r lin k s t h e n e w
o b je c t f ile o th e r o b je c t f ile s
E x e c u t a b le
F ile
T h e L o a d e r p la c e s th e
e x e c u t a b le f ile in t o t h e
m e m o ry
E x e c u t a b le
P r o g r a m in
M e m o ry
15
CPPS - Chapter No 1
16
CPPS - Chapter No 1
17
CPPS - Chapter No 1
Introduction to C Language
C, a high-level language programming language
was developed in early 1970s by Dennis Ritchie at
Bell Laboratories. Over the years, the power and
flexibility of C, together with the availability of high
quality C compilers for computers of all sizes, have
made it a popular language in industry for a wide
variety of applications.
18
CPPS - Chapter No 1
CPPS - Chapter No 1
CPPS - Chapter No 1
21
IDE
Command-Line Development System
CPPS - Chapter No 1
22
CPPS - Chapter No 1
23
CPPS - Chapter No 1
Memory Models
There are five memory models:
Small, Compact, Medium, Large and Huge.
In the Small model your program can have upto 64K of
24
CPPS - Chapter No 1
25
Executable Files
Library and Runtime Files
Header Files
Programmer-Generated Files
CPPS - Chapter No 1
26
27
CPPS - Chapter No 1
28
CPPS - Chapter No 1
29
CPPS - Chapter No 1
30
CPPS - Chapter No 1
for
instance,
31
CPPS - Chapter No 1
32
CPPS - Chapter No 1
33
CPPS - Chapter No 1
34
35
CPPS - Chapter No 1
Compiler Vs Interpreter
Compiler translates the whole source program into
machine language at once while the Interpreter
translates the source program into machine
language line by line.
36
CPPS - Chapter No 1
37
Function Definition
Delimiter
Statement Terminator
The printf ( ) function
void main (void)
{
printf ( This is my first program in C Language. ) ;
}
CPPS - Chapter No 1
called "Functions".
A function in C will always a ( ) at its end. Main( ) is
always be the first function to be executed and is
the one to which control is passed when the
program is executed.
The word "void" preceding the "main" specifies that
the function main( ) will not return a value. The
second "void", in the parenthesis, specifies that the
function takes no arguments.
38
CPPS - Chapter No 1
39
CPPS - Chapter No 1
40
CPPS - Chapter No 1
41
CPPS - Chapter No 1
42
CPPS - Chapter No 1
Output:
I am 20 years old.
43
CPPS - Chapter No 1
CPPS - Chapter No 1
Format Specifier
The format specifier tells the printf( ) where to put
a value in a string and what format to use in
printing the values.
In the previous program, the %d tells the printf( ) to
print the value 20 as a decimal integer.
Then
Th what
h t will
ill be
b the
th method
th d off writing
iti a character
h
t
or floating point number?
Why not simply put the decimal integer into the
original string as compared to the format specifier?
45
CPPS - Chapter No 1
%c
%s
%d
%f
%e
%u
%x
%o
l
single character
string
signed decimal integer
floating point ( decimal notation )
floating point ( exponential notation )
unsigned decimal integer
unsigned hexadecimal integer
unsigned octal integer
prefix used with %d, %u, %x, %o to specify long
integer.
46
CPPS - Chapter No 1
Output:
My name is Ahmad and I am 20 years old.
47
CPPS - Chapter No 1
Output:
The letter j is pronounced as jay.
48
CPPS - Chapter No 1
CPPS - Chapter No 1
CPPS - Chapter No 1
Class Assignment No 1
51