C Programming Language
What is language ?
Language is medium of communication.
If two persons want to communicate with each other , they
have to use a common language.
Like Hindi, English, Punjabi .
What is Programming Language ?
Much in the same way when a user wants to communicate with a computer
,the language that he/she uses for this purpose is known as programming
language .
Like BASIC, COBOL, C, C++, JAVA
At the same time we know that computer understands only one language
that is MACHINE LANGUAGE.
This language comprises of only 0 & 1. Its very difficult for us to learn
this language.
For Example two persons belonging to two different countries , want to
communicate then there may be a problem of common communication
medium.
To solve this problem there is a requirement of translator.
Types of Programming language
Basically there are two types of Programming languages.
Programming. Language
Low Level Languages
High Level Languages
C
Machine Language
Assembly language
C++
JAVA
:.NET
Programming languages
Various programming languages
Some understandable directly by computers
Others require translation steps
Machine language
Natural language of a particular computer
Consists of strings of numbers(1s, 0s)
Instruct computer to perform elementary operations
one at a time
Machine dependant
Programming languages
Assembly Language
English like abbreviations
Translators programs called Assemblers to convert
assembly language programs to machine language.
E.g. add overtime to base pay and store result in gross pay
LOAD
BASEPAY
ADD
OVERPAY
STORE
GROSSPAY
Programming languages
High-level languages
To speed up programming even further
Single statements for accomplishing substantial tasks
Translator programs called Compilers to convert highlevel programs into machine language
E.g. add overtime to base pay and store result in gross pay
grossPay = basePay + overtimePay
Types of Translator
SOURCE
CODE
SOURCE
CODE
SOURCE
CODE
Compiler
OBJECT
CODE
Interpreter
OBJECT
CODE
Assembler
OBJECT
CODE
Basics of C
Why use C?
Mainly because it produces code that runs nearly as fast as
code written in assembly language. Some examples of the use
of C might be:
Operating Systems
Language Compilers
Assemblers
Text Editors
Print Spoolers
Network Drivers
Modern Programs
Data Bases
Language Interpreters
Utilities
Why C Still Useful?
C provides:
Efficiency, high performance and high quality
flexibility and power
many high-level and low-level operations middle level
Stability and small size code
Provide functionality through rich set of function libraries
Gateway for other professional languages like C C++ Java
C is used:
System software Compilers, Editors, embedded systems
data compression, graphics and computational geometry, utility
programs
databases, operating systems, device drivers, system level
routines
there are zillions of lines of C legacy code
Also used in application programs
Software Development Method
Requirement Specification
Problem Definition
Analysis
Refine, Generalize, Decompose the problem definition
Design
Develop Algorithm
Implementation
Write Code
Verification and Testing
Test and Debug the code
Development with C
Four stages
Editing: Writing the source code by using some IDE or editor
Preprocessing or libraries: Already available routines
compiling: translates or converts source to object code for a
specific platform
source code -> object code
linking: resolves external references and produces the
executable module
Portable programs will run on any machine but..
Program correctness and robustness are most important than
program efficiency
History
In 1972 Dennis Ritchie at Bell Labs writes C and in 1978 the
publication of The C Programming Language by Kernighan
& Ritchie caused a revolution in the computing world
In 1983, the American National Standards Institute (ANSI)
established a committee to provide a modern, comprehensive
definition of C. The resulting definition, the ANSI standard, or
"ANSI C", was completed late 1988.
The Beginning of C
BCPL B
Martin Richards
-
Ken Thompson
Dennis Ritchie
History of C
Evolved from two previous languages
BCPL , B
BCPL (Basic Combined Programming Language) used for
writing OS & compilers
B used for creating early versions of UNIX OS
Both were typeless languages
C language evolved from B (Dennis Ritchie Bell labs)
C was developed by Dennis Ritchie at AT & T bell laboratory
of USA in 1972.
History of C
Hardware independent
Programs portable to most computers
Dialects of C
Common C
ANSI C
ANSI/ ISO 9899: 1990
Called American National Standards Institute ANSI C
Case-sensitive
C A Middle Level Language
High-Level Language
+
Low Level Language
C is Middle Level Language
C stands in between these two categories.
Since it was designed to have both:
A relatively good programming efficiency as compared to
Machine Oriented Languages .
A relatively good Machine efficiency as compared to
Problem Oriented Languages .
Thats WHY it is called a Middle Level Language.
Application Areas Of C
C was initially used for systems programming.
A system program forms a portion of the operating
system of the computer or its support utilities.
Operating Systems, Interpreters, Editors, Assembly
programs are usually called system programs.
The UNIX operating system was developed using C.
There are C compilers available for almost all types
of PCs.
A simple Program of C
/* Write a program to print a message */
#include<stdio.h>
#include<conio.h>
void main()
{
printf( C Programming);
getch( );
}
Comment about the program should be enclosed within /* &
*/.
printf() is a function which is used to print messages on the
screen.
main() is a function from which execution of the program
starts.
Here stdio.h is a library file which contains standard
input/output functions , keywords etc.
#include<> is used to define the library file that is to be used
in the program for compiler information.
Compilation & Execution of a Program
C Source Code
C Preprocessor
Expanded C Source Code
C Compiler
Target Assembly Code
Linker
Executable Code
Loader
Output
Basics of C Environment
C systems consist of 3 parts
Environment
Language
C Standard Library
Development environment has 6 phases
Edit
Pre-processor
Compile
Link
Load
Execute
Basics of C Environment
Phase 1
Editor
Phase 2 Preprocessor
Phase 3
Phase 4
Compiler
Linker
Disk
Program edited in
Editor and stored
on disk
Disk
Preprocessor
program processes
the code
Disk
Disk
Creates object code
and stores on disk
Links object code
with libraries and
stores on disk
Basics of C Environment
Primary memory
Phase 5
Loader
Primary memory
Phase 6
CPU
Puts program in
memory
Takes each instruction
and executes it storing
new data values
Execution Process of a Program
PROCESS
SHORT CUT
FILE NAME
Save
Compile
F2
Alt + F9
abc.c
abc.obj
Execute
Ctrl + F9
abc.exe
Back up
Again F2
abc.bak
Escape Sequence
\n
\t
\r
\a
\\
\
new line
tab
carriage return
alert
backslash
double quote
Thanks