The C Programming Language
INTRODUCTION
The History of C
Originally designed for and implemented on
the UNIX OS – on DEC PDP 11 – by Dennis
Ritchie at Bell Labs.
UNIX – written in C
Extremely popular and widely used
Several flavours – ANSI
C++ evolved from C & has more powerful
object oriented features -- Bjarne Stroustrup.
FEATURES
System independence
Limited Data types
High efficiency
Structured programming
Advantages
Simple and orderly – Compilers can run on small
machines
Efficiency – C Programmes translate into machine
code more efficiently – faster and smaller exe code.
Portability – Write in C and run on several OS’es –
Cray, DEC, SUN with little or no modification.
Structured Programming organised
Flexibility – few restrictions.
Disadvantages
Flexibility of C -- problem for an
inexperienced programmer – mistake
results in a valid – unwanted interpretation.
Code Sparse – Cryptic and Confusing.
B’coz ‘C’ imposes few restrictions –
bugs can bury themselves more in C than in
other languages.
Compilers and Interpreters
Translates source file of High-Level Language (HLL)
code into object file of machine language code
Compile-time vs Run-time
Development Cycle:
* Edit - Compile - Link - Load/Execute
Final result is machine code: runs quickly
Compilers may generate efficient, optimised code
Compiled HLLs: Modula-2, C, Pascal, Eiffel,
FORTRAN...
INTERPRETERS
Translates HLL statements to machine-code
procedure calls directly
Interactive - results are immediate
eg. Unix Shell
Interpreted language programs run more slowly
than those created using compiled languages
Examples: BASICA, Lisp, PERL, UNIX Shell...
Does distinguish lower & upper case
letters.
Keywords can not be used as
variables.
Basic structure of
C - Programming
Documentation section
Link section
Definition section
Global declaration section
Function section- main(),
1. Declaration part and
2. Executable part
Subprogram section- Functions1, 2, 3 …. Etc.
Execution of C
Programs
4 Steps:-
1. Creating the program
2. Compiling
3. Linking
4. Executing
Characters in C
4 Categories:
1. Letters – A-Z, a-z (52)
2. Digits - 0-9 (10)
3. Special Characters- ,.;:‘“!|/\~$
% # & ^ * - + < > ( ) [ ] { } ?@ (29)
4. White Spaces- Blanks, Tab, Carriage
return, form feed, new line ( 5)
Fundamental Data
Types
4 types
1. Integer- ‘int’
2. Character- ‘char’
3. Floating point- ‘float’
4. Double precision floating point -
‘double’
Input- Output
instructions
Input – getchar(); scanf();
Output - putchar(); printf()’;