SlideShare a Scribd company logo
1 of 36
Introduction to C
Programming
Introduction
Books
 “The Waite Group’s Turbo C Programming
for PC”, Robert Lafore, SAMS
 Teach Yourself C : Herbert Schildt
 Programming in ANSI C- E. Balagurusamy
What is C?
 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 general-
purpose 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.
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…..
 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 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
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)
** Typeless – no datatypes. Every data item occupied 1 word in memory.
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 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
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
Editor DiskPhase 1
Program edited in
Editor and stored
on disk
Preprocessor DiskPhase 2
Preprocessor
program processes
the code
Compiler DiskPhase 3
Creates object code
and stores on disk
Linker DiskPhase 4
Links object code
with libraries and
stores on disk
Basics of C Environment
LoaderPhase 5
Puts program in
memory
Primary memory
CPUPhase 6
Takes each instruction
and executes it storing
new data values
Primary memory
Simple C Program
/* A first C Program*/
#include <stdio.h>
void main()
{
printf("Hello World n");
}
Simple C Program
 Line 1: #include <stdio.h>
 As part of compilation, the C compiler runs a program
called the C preprocessor. The preprocessor is able to
add and remove code from your source file.
 In this case, the directive #include tells the
preprocessor to include code from the file stdio.h.
 This file contains declarations for functions that the
program needs to use. A declaration for the printf
function is in this file.
Simple C Program
 Line 2: void main()
 This statement declares the main function.
 A C program can contain many functions but must
always have one main function.
 A function is a self-contained module of code that can
accomplish some task.
 Functions are examined later.
 The "void" specifies the return type of main. In this case,
nothing is returned to the operating system.
Simple C Program
 Line 3: {
 This opening bracket denotes the start of the program.
Simple C Program
 Line 4: printf("Hello World From Aboutn");
 Printf is a function from a standard C library that is used
to print strings to the standard output, normally your
screen.
 The compiler links code from these standard libraries to
the code you have written to produce the final
executable.
 The "n" is a special format modifier that tells the printf
to put a line feed at the end of the line.
 If there were another printf in this program, its string
would print on the next line.
Simple C Program
 Line 5: }
 This closing bracket denotes the end of the program.
Escape Sequence
 n new line
 t tab
 r carriage return
 a alert
  backslash
 ” double quote
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 Algebraic C
Addition(+) f+7 f+7
Subtraction (-) p-c p-c
Multiplication(*) bm b*m
Division(/) x/y, x , x y x/y
Modulus(%) r mod s 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
 Equality operators
• ==
• !=
 Relational operators
• <
• >
• <=
• >=
Summary of precedence order
Operator Associativity
() left to right
* / % left to right
+ - left to right
< <= > >= left to right
== != left to right
= left to right
Assignment operators
 =
 +=
 -=
 *=
 /=
 %=
Increment/ decrement operators
 ++ ++a
 ++ a++
 -- --a
 -- a--
Increment/ decrement operators
main()
{
int c;
c = 5;
printf(“%dn”, c);
printf(“%dn”, c++);
printf(“%dnn”, c);
c = 5;
printf(“%dn”, c);
printf(“%dn”, ++c);
printf(“%dn”, c);
return 0;
}
5
5
6
5
6
6
Thank You
 Thank You

More Related Content

What's hot (20)

Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
C functions
C functionsC functions
C functions
 
C tokens
C tokensC tokens
C tokens
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
C tutorial
C tutorialC tutorial
C tutorial
 
Loops in c
Loops in cLoops in c
Loops in c
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
History of c
History of cHistory of c
History of c
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Function in C
Function in CFunction in C
Function in C
 
structure and union
structure and unionstructure and union
structure and union
 
How to execute a C program
How to execute a C  program How to execute a C  program
How to execute a C program
 

Viewers also liked

Viewers also liked (12)

structured programming Introduction to c fundamentals
structured programming Introduction to c fundamentalsstructured programming Introduction to c fundamentals
structured programming Introduction to c fundamentals
 
Mickey mouse
Mickey mouseMickey mouse
Mickey mouse
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Green chemistry
Green chemistryGreen chemistry
Green chemistry
 
Why C is Called Structured Programming Language
Why C is Called Structured Programming LanguageWhy C is Called Structured Programming Language
Why C is Called Structured Programming Language
 
Programmer ppt
Programmer pptProgrammer ppt
Programmer ppt
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Biotechnology
BiotechnologyBiotechnology
Biotechnology
 
Biotech & medicine.ppt
Biotech & medicine.pptBiotech & medicine.ppt
Biotech & medicine.ppt
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
Solar panel Technology ppt
Solar panel Technology pptSolar panel Technology ppt
Solar panel Technology ppt
 
Solar energy ppt
Solar energy pptSolar energy ppt
Solar energy ppt
 

Similar to Introduction to C programming

What is turbo c and how it works
What is turbo c and how it worksWhat is turbo c and how it works
What is turbo c and how it worksMark John Lado, MIT
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxCoolGamer16
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c languagefarishah
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptxMugilvannan11
 
Bsc cs i pic u-1 introduction to c language
Bsc cs i pic u-1 introduction to c languageBsc cs i pic u-1 introduction to c language
Bsc cs i pic u-1 introduction to c languageRai University
 
introduction to c language
 introduction to c language introduction to c language
introduction to c languageRai University
 
Mca i pic u-1 introduction to c language
Mca i pic u-1 introduction to c languageMca i pic u-1 introduction to c language
Mca i pic u-1 introduction to c languageRai University
 
Btech i pic u-1 introduction to c language
Btech i pic u-1 introduction to c languageBtech i pic u-1 introduction to c language
Btech i pic u-1 introduction to c languageRai University
 
Diploma ii cfpc u-1 introduction to c language
Diploma ii  cfpc u-1 introduction to c languageDiploma ii  cfpc u-1 introduction to c language
Diploma ii cfpc u-1 introduction to c languageRai University
 
Chapter 1 Introduction to C .pptx
Chapter 1 Introduction to C .pptxChapter 1 Introduction to C .pptx
Chapter 1 Introduction to C .pptxAbdalla536859
 
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYC LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYRajeshkumar Reddy
 
Intro to cprogramming
Intro to cprogrammingIntro to cprogramming
Intro to cprogrammingskashwin98
 
C programming presentation(final)
C programming presentation(final)C programming presentation(final)
C programming presentation(final)aaravSingh41
 

Similar to Introduction to C programming (20)

C PROGRAMMING
C PROGRAMMINGC PROGRAMMING
C PROGRAMMING
 
C intro
C introC intro
C intro
 
01 c
01 c01 c
01 c
 
What is turbo c and how it works
What is turbo c and how it worksWhat is turbo c and how it works
What is turbo c and how it works
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptx
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c language
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
 
Bsc cs i pic u-1 introduction to c language
Bsc cs i pic u-1 introduction to c languageBsc cs i pic u-1 introduction to c language
Bsc cs i pic u-1 introduction to c language
 
introduction to c language
 introduction to c language introduction to c language
introduction to c language
 
Mca i pic u-1 introduction to c language
Mca i pic u-1 introduction to c languageMca i pic u-1 introduction to c language
Mca i pic u-1 introduction to c language
 
Btech i pic u-1 introduction to c language
Btech i pic u-1 introduction to c languageBtech i pic u-1 introduction to c language
Btech i pic u-1 introduction to c language
 
Diploma ii cfpc u-1 introduction to c language
Diploma ii  cfpc u-1 introduction to c languageDiploma ii  cfpc u-1 introduction to c language
Diploma ii cfpc u-1 introduction to c language
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Chapter 1 Introduction to C .pptx
Chapter 1 Introduction to C .pptxChapter 1 Introduction to C .pptx
Chapter 1 Introduction to C .pptx
 
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYC LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
 
Intro to cprogramming
Intro to cprogrammingIntro to cprogramming
Intro to cprogramming
 
Csc240 -lecture_3
Csc240  -lecture_3Csc240  -lecture_3
Csc240 -lecture_3
 
Basic c
Basic cBasic c
Basic c
 
C tutorials
C tutorialsC tutorials
C tutorials
 
C programming presentation(final)
C programming presentation(final)C programming presentation(final)
C programming presentation(final)
 

More from Rokonuzzaman Rony (20)

Course outline for c programming
Course outline for c  programming Course outline for c  programming
Course outline for c programming
 
Pointer
PointerPointer
Pointer
 
Operator Overloading & Type Conversions
Operator Overloading & Type ConversionsOperator Overloading & Type Conversions
Operator Overloading & Type Conversions
 
Constructors & Destructors
Constructors  & DestructorsConstructors  & Destructors
Constructors & Destructors
 
Classes and objects in c++
Classes and objects in c++Classes and objects in c++
Classes and objects in c++
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
 
Humanitarian task and its importance
Humanitarian task and its importanceHumanitarian task and its importance
Humanitarian task and its importance
 
Structure
StructureStructure
Structure
 
Pointers
 Pointers Pointers
Pointers
 
Loops
LoopsLoops
Loops
 
Array
ArrayArray
Array
 
Constants, Variables, and Data Types
Constants, Variables, and Data TypesConstants, Variables, and Data Types
Constants, Variables, and Data Types
 
C Programming language
C Programming languageC Programming language
C Programming language
 
User defined functions
User defined functionsUser defined functions
User defined functions
 
Numerical Method 2
Numerical Method 2Numerical Method 2
Numerical Method 2
 
Numerical Method
Numerical Method Numerical Method
Numerical Method
 
Data structures
Data structuresData structures
Data structures
 
Data structures
Data structures Data structures
Data structures
 
Data structures
Data structures Data structures
Data structures
 

Recently uploaded

Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 

Recently uploaded (20)

Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 

Introduction to C programming

  • 2. Books  “The Waite Group’s Turbo C Programming for PC”, Robert Lafore, SAMS  Teach Yourself C : Herbert Schildt  Programming in ANSI C- E. Balagurusamy
  • 3. What is C?  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 general- purpose language because of its popularity with programmers.
  • 4. 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
  • 5. 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.
  • 6. 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
  • 7. 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
  • 8. 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
  • 9. 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
  • 10. 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
  • 11. 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
  • 12. 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) ** Typeless – no datatypes. Every data item occupied 1 word in memory.
  • 13. 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
  • 14. 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
  • 15. 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
  • 16. Basics of C Environment Editor DiskPhase 1 Program edited in Editor and stored on disk Preprocessor DiskPhase 2 Preprocessor program processes the code Compiler DiskPhase 3 Creates object code and stores on disk Linker DiskPhase 4 Links object code with libraries and stores on disk
  • 17. Basics of C Environment LoaderPhase 5 Puts program in memory Primary memory CPUPhase 6 Takes each instruction and executes it storing new data values Primary memory
  • 18. Simple C Program /* A first C Program*/ #include <stdio.h> void main() { printf("Hello World n"); }
  • 19. Simple C Program  Line 1: #include <stdio.h>  As part of compilation, the C compiler runs a program called the C preprocessor. The preprocessor is able to add and remove code from your source file.  In this case, the directive #include tells the preprocessor to include code from the file stdio.h.  This file contains declarations for functions that the program needs to use. A declaration for the printf function is in this file.
  • 20. Simple C Program  Line 2: void main()  This statement declares the main function.  A C program can contain many functions but must always have one main function.  A function is a self-contained module of code that can accomplish some task.  Functions are examined later.  The "void" specifies the return type of main. In this case, nothing is returned to the operating system.
  • 21. Simple C Program  Line 3: {  This opening bracket denotes the start of the program.
  • 22. Simple C Program  Line 4: printf("Hello World From Aboutn");  Printf is a function from a standard C library that is used to print strings to the standard output, normally your screen.  The compiler links code from these standard libraries to the code you have written to produce the final executable.  The "n" is a special format modifier that tells the printf to put a line feed at the end of the line.  If there were another printf in this program, its string would print on the next line.
  • 23. Simple C Program  Line 5: }  This closing bracket denotes the end of the program.
  • 24. Escape Sequence  n new line  t tab  r carriage return  a alert  backslash  ” double quote
  • 25. 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”
  • 26. Arithmetic in C C operation Algebraic C Addition(+) f+7 f+7 Subtraction (-) p-c p-c Multiplication(*) bm b*m Division(/) x/y, x , x y x/y Modulus(%) r mod s r%s
  • 27. Precedence order  Highest to lowest • () • *, /, % • +, -
  • 28. Example Algebra: z = pr%q+w/x-y C: z = p * r % q + w / x – y ; Precedence: 1 2 4 3 5
  • 29. Example Algebra: a(b+c)+ c(d+e) C: a * ( b + c ) + c * ( d + e ) ; Precedence: 3 1 5 4 2
  • 30. 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
  • 31. Decision Making  Equality operators • == • !=  Relational operators • < • > • <= • >=
  • 32. Summary of precedence order Operator Associativity () left to right * / % left to right + - left to right < <= > >= left to right == != left to right = left to right
  • 33. Assignment operators  =  +=  -=  *=  /=  %=
  • 34. Increment/ decrement operators  ++ ++a  ++ a++  -- --a  -- a--
  • 35. Increment/ decrement operators main() { int c; c = 5; printf(“%dn”, c); printf(“%dn”, c++); printf(“%dnn”, c); c = 5; printf(“%dn”, c); printf(“%dn”, ++c); printf(“%dn”, c); return 0; } 5 5 6 5 6 6