Documente Academic
Documente Profesional
Documente Cultură
Introduction
Books
The Waite Groups Turbo C Programming for PC, Robert Lafore, SAMS C How to Program, H.M. Deitel, P.J. Deitel, Prentice Hall
What is C?
A language written by Brian Kernighan and Dennis Ritchie. This was to be the language that UNIX was written in to become the first "portable" language
In recent years C has been used as a generalpurpose language because of its popularity with programmers.
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
Mainly because of the portability that writing standard C programs can offer
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.
C provides:
Efficiency, high performance and high quality s/ws 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
Requirement Specification
Problem Definition
Analysis
Refine, Generalize, Decompose the problem definition
Design
Develop Algorithm
Implementation
Write 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.. Note! Program correctness and robustness are most important than program efficiency
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
STORE
OVERPAY
GROSSPAY
Programming languages
High-level languages
To speed up programming even further Single statements for accomplishing substantial tasks Translator programs called Compilers to convert high-level programs into machine language E.g. add overtime to base pay and store result in gross pay grossPay = basePay + overtimePay
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)
History of C
Case-sensitive
C Standard Library
Two parts to learning the C world Learn C itself Take advantage of rich collection of existing functions called C Standard Library Avoid reinventing the wheel SW reusability
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 Disk Program edited in Editor and stored on disk Preprocessor program processes the code Creates object code and stores on disk Links object code with libraries and stores on disk
Phase 2 Preprocessor
Disk
Phase 3
Compiler
Disk
Phase 4
Linker
Disk
Basics of C Environment
Primary memory
Phase 5 Loader Puts program in memory
CPU
Simple C Program
/* A first C Program*/ #include <stdio.h> void main() { printf("Hello World \n");
Simple C Program
Simple C Program
Simple C Program
Line 3: {
This opening bracket denotes the start of the program.
Simple C Program
Simple C Program
Line 5: }
This closing bracket denotes the end of the program.
Escape Sequence
\n \t \r \a \\ \
Memory concepts
Every variable has a name, type and value Variable names correspond to locations in computer memory New value over-writes the previous value Destructive read-in Value reading called Non-destructive read-out
Arithmetic in C
C operation Addition(+) Subtraction (-) Multiplication(*) Division(/) Modulus(%) Algebraic C f+7 p-c bm x/y, x , x y r mod s f+7 p-c b*m x/y r%s
Precedence order
Highest to lowest () *, /, % +, -
Example
Algebra: z = pr%q+w/x-y
C:
z = p * r % q + w / x y ;
Precedence:
1 2 4 3 5
Example
Algebra: a(b+c)+ c(d+e)
C:
a * ( b + c ) + c * ( d + e ) ;
Precedence:
3 1 5 4 2
Decision Making
Checking falsity or truth of a statement Equality operators have lower precedence than relational operators Relational operators have same precedence Both associate from left to right
Decision Making
Assignment operators
= += -= *= /= %=
++ ++ ---
5 5 6
5 6 6
return 0;
}
Thank You
Thank You