SlideShare a Scribd company logo
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

PPTX
Introduction to c programming
PPT
Bubble sort
PPTX
Antipsychotic drugs ppt
PPSX
INTRODUCTION TO C PROGRAMMING
PPT
Basics of C programming
PPT
Carbon compounds (ppt)
PPTX
C language ppt
PPT
Chapter 12
Introduction to c programming
Bubble sort
Antipsychotic drugs ppt
INTRODUCTION TO C PROGRAMMING
Basics of C programming
Carbon compounds (ppt)
C language ppt
Chapter 12

What's hot (20)

PPTX
Unit1 principle of programming language
DOCX
Basic structure of c programming
PPTX
Packages In Python Tutorial
PPTX
Asymptotic notations
PPTX
C tokens
PPTX
Character set of c
PDF
Preprocessor
PPTX
Presentation on Function in C Programming
PPTX
Inline function
PPTX
PPTX
structured programming
PDF
Introduction to c++ ppt 1
PPT
Computer Organization and Architecture.
PPTX
Presentation on C++ Programming Language
PPTX
Functions in c
PPSX
Function in c
PPTX
Function in C program
PPTX
C Programming Unit-1
PPTX
Polymorphism in c++(ppt)
PPT
Structure of a C program
Unit1 principle of programming language
Basic structure of c programming
Packages In Python Tutorial
Asymptotic notations
C tokens
Character set of c
Preprocessor
Presentation on Function in C Programming
Inline function
structured programming
Introduction to c++ ppt 1
Computer Organization and Architecture.
Presentation on C++ Programming Language
Functions in c
Function in c
Function in C program
C Programming Unit-1
Polymorphism in c++(ppt)
Structure of a C program
Ad

Viewers also liked (11)

PDF
structured programming Introduction to c fundamentals
PPTX
PPTX
Introduction to C Programming
PPTX
Green chemistry
PPT
Why C is Called Structured Programming Language
PPTX
Programmer ppt
PPTX
PPT
Biotechnology
PPTX
Biotech & medicine.ppt
PPTX
Solar panel Technology ppt
PPT
Solar energy ppt
structured programming Introduction to c fundamentals
Introduction to C Programming
Green chemistry
Why C is Called Structured Programming Language
Programmer ppt
Biotechnology
Biotech & medicine.ppt
Solar panel Technology ppt
Solar energy ppt
Ad

Similar to Introduction to C programming (20)

PPT
C PROGRAMMING
PPT
C intro
PPT
01 c
PPT
What is turbo c and how it works
PPTX
Basics of C Lecture 2[16097].pptx
PDF
Introduction of c language
PPTX
Unit-1_c.pptx you from the heart of the day revision
PDF
C class basic programming 1 PPT mayanka (1).pdf
PPTX
C Programming UNIT 1.pptx
PPTX
Bsc cs i pic u-1 introduction to c language
PPTX
introduction to c language
PPTX
Mca i pic u-1 introduction to c language
PPTX
Btech i pic u-1 introduction to c language
PPTX
Diploma ii cfpc u-1 introduction to c language
PPTX
Introduction to C Programming
PPTX
Chapter 1 Introduction to C .pptx
DOCX
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
PPTX
Intro to cprogramming
PPTX
Csc240 -lecture_3
DOC
Basic c
C PROGRAMMING
C intro
01 c
What is turbo c and how it works
Basics of C Lecture 2[16097].pptx
Introduction of c language
Unit-1_c.pptx you from the heart of the day revision
C class basic programming 1 PPT mayanka (1).pdf
C Programming UNIT 1.pptx
Bsc cs i pic u-1 introduction to c language
introduction to c language
Mca 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
Introduction to C Programming
Chapter 1 Introduction to C .pptx
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
Intro to cprogramming
Csc240 -lecture_3
Basic c

More from Rokonuzzaman Rony (20)

PPTX
Course outline for c programming
PPTX
PPTX
Operator Overloading & Type Conversions
PPTX
Constructors & Destructors
PPTX
Classes and objects in c++
PPTX
Functions in c++
PPTX
Object Oriented Programming with C++
PPTX
Humanitarian task and its importance
PPTX
PPTX
PPTX
Constants, Variables, and Data Types
PPTX
C Programming language
PPTX
User defined functions
PPTX
Numerical Method 2
PPT
Numerical Method
PPTX
Data structures
PPT
Data structures
PPTX
Data structures
Course outline for c programming
Operator Overloading & Type Conversions
Constructors & Destructors
Classes and objects in c++
Functions in c++
Object Oriented Programming with C++
Humanitarian task and its importance
Constants, Variables, and Data Types
C Programming language
User defined functions
Numerical Method 2
Numerical Method
Data structures
Data structures
Data structures

Recently uploaded (20)

PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PPTX
How to Manage Loyalty Points in Odoo 18 Sales
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
PDF
LDMMIA Reiki Yoga S2 L3 Vod Sample Preview
PPTX
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
PPTX
Software Engineering BSC DS UNIT 1 .pptx
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
PDF
Sunset Boulevard Student Revision Booklet
PPTX
Odoo 18 Sales_ Managing Quotation Validity
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
PDF
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
PDF
What Is Coercive Control? Understanding and Recognizing Hidden Abuse
PPTX
Revamp in MTO Odoo 18 Inventory - Odoo Slides
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
High Ground Student Revision Booklet Preview
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
Open Quiz Monsoon Mind Game Final Set.pptx
How to Manage Loyalty Points in Odoo 18 Sales
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
LDMMIA Reiki Yoga S2 L3 Vod Sample Preview
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Software Engineering BSC DS UNIT 1 .pptx
Information Texts_Infographic on Forgetting Curve.pptx
Sunset Boulevard Student Revision Booklet
Odoo 18 Sales_ Managing Quotation Validity
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
What Is Coercive Control? Understanding and Recognizing Hidden Abuse
Revamp in MTO Odoo 18 Inventory - Odoo Slides
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
NOI Hackathon - Summer Edition - GreenThumber.pptx
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
High Ground Student Revision Booklet Preview

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