SlideShare une entreprise Scribd logo
1  sur  36
Introduction to C
 Programming



   Introduction
Books

s   “The Waite Group’s Turbo C Programming for PC”,
    Robert Lafore, SAMS

s   “C How to Program”, H.M. Deitel, P.J. Deitel,
    Prentice Hall
What is C?
s   C
    s   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?
    s   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
s   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

s   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?
s   C provides:
    x   Efficiency, high performance and high quality s/ws
    x   flexibility and power
    x   many high-level and low-level operations  middle level
    x   Stability and small size code
    x   Provide functionality through rich set of function libraries
    x   Gateway for other professional languages like C  C++  Java


s   C is used:
    x   System software Compilers, Editors, embedded systems
    x   data compression, graphics and computational geometry, utility
        programs
    x   databases, operating systems, device drivers, system level
        routines
    x   there are zillions of lines of C legacy code
    x   Also used in application programs
Software Development Method
s   Requirement Specification
    – Problem Definition
s   Analysis
    – Refine, Generalize, Decompose the problem definition
s   Design
    – Develop Algorithm
s   Implementation
    – Write Code
s   Verification and Testing
    – Test and Debug the code
Development with C
s   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
s   Various programming languages
s   Some understandable directly by computers
s   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
s   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
s   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
s   Evolved from two previous languages
     – BCPL , B
s   BCPL (Basic Combined Programming Language) used
    for writing OS & compilers
s   B used for creating early versions of UNIX OS
s   Both were “typeless” languages
s   C language evolved from B (Dennis Ritchie – Bell labs)




    ** Typeless – no datatypes. Every data item occupied 1 word in memory.
History of C
s   Hardware independent
s   Programs portable to most computers
s   Dialects of C
    – Common C
    – ANSI C
       • ANSI/ ISO 9899: 1990
       • Called American National Standards Institute ANSI C
s   Case-sensitive
C Standard Library
s   Two parts to learning the “C” world
     – Learn C itself
     – Take advantage of rich collection of existing functions
       called C Standard Library
s   Avoid reinventing the wheel
s   SW reusability
Basics of C Environment
s   C systems consist of 3 parts
     – Environment
     – Language
     – C Standard Library
s   Development environment has 6 phases
     – Edit
     – Pre-processor
     – Compile
     – Link
     – Load
     – Execute
Basics of C Environment
                              Program edited in
Phase 1    Editor      Disk   Editor and stored
                              on disk
                              Preprocessor
Phase 2 Preprocessor   Disk   program processes
                              the code
                              Creates object code
Phase 3   Compiler     Disk   and stores on disk

                              Links object code
Phase 4    Linker      Disk   with libraries and
                              stores on disk
Basics of C Environment

                    Primary memory
                                       Puts program in
Phase 5   Loader                       memory




                    Primary memory
                                     Takes each instruction
Phase 6    CPU                       and executes it storing
                                     new data values
Simple C Program
/* A first C Program*/

#include <stdio.h>

void main()

{
     printf("Hello World n");

}
Simple C Program
s   Line 1: #include <stdio.h>

s   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.
s   In this case, the directive #include tells the
    preprocessor to include code from the file stdio.h.
s   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
s   Line 2: void main()

s   This statement declares the main function.
s   A C program can contain many functions but must
    always have one main function.
s   A function is a self-contained module of code that can
    accomplish some task.
s   Functions are examined later.
s   The "void" specifies the return type of main. In this case,
    nothing is returned to the operating system.
Simple C Program
s   Line 3: {

s   This opening bracket denotes the start of the program.
Simple C Program
s   Line 4: printf("Hello World From Aboutn");

s   Printf is a function from a standard C library that is used
    to print strings to the standard output, normally your
    screen.
s   The compiler links code from these standard libraries to
    the code you have written to produce the final
    executable.
s   The "n" is a special format modifier that tells the printf
    to put a line feed at the end of the line.
s   If there were another printf in this program, its string
    would print on the next line.
Simple C Program
s   Line 5: }
s     This closing bracket denotes the end of the program.
Escape Sequence
s   n   new line
s   t   tab
s   r   carriage return
s   a   alert
s      backslash
s   ”   double quote
Memory concepts
s   Every variable has a name, type and value
s   Variable names correspond to locations in computer
    memory
s   New value over-writes the previous value– “Destructive
    read-in”
s   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
s   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
s   Checking falsity or truth of a statement
s   Equality operators have lower precedence than
    relational operators
s   Relational operators have same precedence
s   Both associate from left to right
Decision Making
s   Equality operators
        • ==
        • !=
s   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
s   =
s   +=
s   -=
s   *=
s   /=
s   %=
Increment/ decrement operators
s   ++    ++a
s   ++    a++
s   --    --a
s   --    a--
Increment/ decrement operators
main()
{
     int c;
     c = 5;
                              5
     printf(“%dn”, c);       5
     printf(“%dn”, c++);     6
     printf(“%dnn”, c);

       c = 5;
       printf(“%dn”, c);     5
                              6
       printf(“%dn”, ++c);   6
       printf(“%dn”, c);

    return 0;
}
Thank You
s   Thank You

Contenu connexe

Tendances

Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingManoj Tyagi
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingAkshay Ithape
 
An Overview of Programming C
An Overview of Programming CAn Overview of Programming C
An Overview of Programming CNishargo Nigar
 
Introduction of c programming
Introduction of c programmingIntroduction of c programming
Introduction of c programmingTarun Sharma
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c languagefarishah
 
Introduction to programming with c,
Introduction to programming with c,Introduction to programming with c,
Introduction to programming with c,Hossain Md Shakhawat
 
COM1407: Introduction to C Programming
COM1407: Introduction to C Programming COM1407: Introduction to C Programming
COM1407: Introduction to C Programming Hemantha Kulathilake
 
Lecture 1 Compiler design , computation
Lecture 1 Compiler design , computation Lecture 1 Compiler design , computation
Lecture 1 Compiler design , computation Rebaz Najeeb
 
Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7Shipra Swati
 
cmp104 lec 8
cmp104 lec 8cmp104 lec 8
cmp104 lec 8kapil078
 
Programming language
Programming languageProgramming language
Programming languageMakku-Sama
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingMOHAMAD NOH AHMAD
 
Brief introduction to the c programming language
Brief introduction to the c programming languageBrief introduction to the c programming language
Brief introduction to the c programming languageKumar Gaurav
 

Tendances (20)

Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
An Overview of Programming C
An Overview of Programming CAn Overview of Programming C
An Overview of Programming C
 
Introduction of c programming
Introduction of c programmingIntroduction of c programming
Introduction of c programming
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c language
 
Unit1 cd
Unit1 cdUnit1 cd
Unit1 cd
 
Introduction to programming with c,
Introduction to programming with c,Introduction to programming with c,
Introduction to programming with c,
 
Csc240 -lecture_3
Csc240  -lecture_3Csc240  -lecture_3
Csc240 -lecture_3
 
COM1407: Introduction to C Programming
COM1407: Introduction to C Programming COM1407: Introduction to C Programming
COM1407: Introduction to C Programming
 
C programming
C programmingC programming
C programming
 
Ch1 Introducing C
Ch1 Introducing CCh1 Introducing C
Ch1 Introducing C
 
Lecture 1 Compiler design , computation
Lecture 1 Compiler design , computation Lecture 1 Compiler design , computation
Lecture 1 Compiler design , computation
 
Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
Overview of c
Overview of cOverview of c
Overview of c
 
cmp104 lec 8
cmp104 lec 8cmp104 lec 8
cmp104 lec 8
 
Programming language
Programming languageProgramming language
Programming language
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Brief introduction to the c programming language
Brief introduction to the c programming languageBrief introduction to the c programming language
Brief introduction to the c programming language
 
C basics
C   basicsC   basics
C basics
 

Similaire à 01 c

Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programmingRokonuzzaman Rony
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptxMugilvannan11
 
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
 
Programming Fundamentals and Programming Languages Concepts Translators
Programming Fundamentals and Programming Languages Concepts TranslatorsProgramming Fundamentals and Programming Languages Concepts Translators
Programming Fundamentals and Programming Languages Concepts Translatorsimtiazalijoono
 
Chowtodoprogram solutions
Chowtodoprogram solutionsChowtodoprogram solutions
Chowtodoprogram solutionsMusa Gürbüz
 
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
 
C programming presentation(final)
C programming presentation(final)C programming presentation(final)
C programming presentation(final)aaravSingh41
 
introduction to c language
 introduction to c language introduction to c language
introduction to c languageRai University
 
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfINTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfSubramanyambharathis
 
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
 
Understanding C and its Applications.pdf
Understanding C and its Applications.pdfUnderstanding C and its Applications.pdf
Understanding C and its Applications.pdfAdeleHansley
 

Similaire à 01 c (20)

C_Intro.ppt
C_Intro.pptC_Intro.ppt
C_Intro.ppt
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
 
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
 
C programming part1
C programming part1C programming part1
C programming part1
 
C session 1.pptx
C session 1.pptxC session 1.pptx
C session 1.pptx
 
Programming Fundamentals and Programming Languages Concepts Translators
Programming Fundamentals and Programming Languages Concepts TranslatorsProgramming Fundamentals and Programming Languages Concepts Translators
Programming Fundamentals and Programming Languages Concepts Translators
 
Basic c
Basic cBasic c
Basic c
 
Learn C Language
Learn C LanguageLearn C Language
Learn C Language
 
C language unit-1
C language unit-1C language unit-1
C language unit-1
 
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDYC LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
 
C languaGE UNIT-1
C languaGE UNIT-1C languaGE UNIT-1
C languaGE UNIT-1
 
Chowtodoprogram solutions
Chowtodoprogram solutionsChowtodoprogram solutions
Chowtodoprogram solutions
 
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
 
Presentation 2.ppt
Presentation 2.pptPresentation 2.ppt
Presentation 2.ppt
 
C programming presentation(final)
C programming presentation(final)C programming presentation(final)
C programming presentation(final)
 
introduction to c language
 introduction to c language introduction to c language
introduction to c language
 
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfINTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
 
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
 
Understanding C and its Applications.pdf
Understanding C and its Applications.pdfUnderstanding C and its Applications.pdf
Understanding C and its Applications.pdf
 

Dernier

Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsRommel Regala
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 

Dernier (20)

Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World Politics
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 

01 c

  • 1. Introduction to C Programming Introduction
  • 2. Books s “The Waite Group’s Turbo C Programming for PC”, Robert Lafore, SAMS s “C How to Program”, H.M. Deitel, P.J. Deitel, Prentice Hall
  • 3. What is C? s C s 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? s 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 s 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 s 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? s C provides: x Efficiency, high performance and high quality s/ws x flexibility and power x many high-level and low-level operations  middle level x Stability and small size code x Provide functionality through rich set of function libraries x Gateway for other professional languages like C  C++  Java s C is used: x System software Compilers, Editors, embedded systems x data compression, graphics and computational geometry, utility programs x databases, operating systems, device drivers, system level routines x there are zillions of lines of C legacy code x Also used in application programs
  • 7. Software Development Method s Requirement Specification – Problem Definition s Analysis – Refine, Generalize, Decompose the problem definition s Design – Develop Algorithm s Implementation – Write Code s Verification and Testing – Test and Debug the code
  • 8. Development with C s 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 s Various programming languages s Some understandable directly by computers s 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 s 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 s 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 s Evolved from two previous languages – BCPL , B s BCPL (Basic Combined Programming Language) used for writing OS & compilers s B used for creating early versions of UNIX OS s Both were “typeless” languages s C language evolved from B (Dennis Ritchie – Bell labs) ** Typeless – no datatypes. Every data item occupied 1 word in memory.
  • 13. History of C s Hardware independent s Programs portable to most computers s Dialects of C – Common C – ANSI C • ANSI/ ISO 9899: 1990 • Called American National Standards Institute ANSI C s Case-sensitive
  • 14. C Standard Library s Two parts to learning the “C” world – Learn C itself – Take advantage of rich collection of existing functions called C Standard Library s Avoid reinventing the wheel s SW reusability
  • 15. Basics of C Environment s C systems consist of 3 parts – Environment – Language – C Standard Library s Development environment has 6 phases – Edit – Pre-processor – Compile – Link – Load – Execute
  • 16. Basics of C Environment Program edited in Phase 1 Editor Disk Editor and stored on disk Preprocessor Phase 2 Preprocessor Disk program processes the code Creates object code Phase 3 Compiler Disk and stores on disk Links object code Phase 4 Linker Disk with libraries and stores on disk
  • 17. Basics of C Environment Primary memory Puts program in Phase 5 Loader memory Primary memory Takes each instruction Phase 6 CPU and executes it storing new data values
  • 18. Simple C Program /* A first C Program*/ #include <stdio.h> void main() { printf("Hello World n"); }
  • 19. Simple C Program s Line 1: #include <stdio.h> s 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. s In this case, the directive #include tells the preprocessor to include code from the file stdio.h. s 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 s Line 2: void main() s This statement declares the main function. s A C program can contain many functions but must always have one main function. s A function is a self-contained module of code that can accomplish some task. s Functions are examined later. s The "void" specifies the return type of main. In this case, nothing is returned to the operating system.
  • 21. Simple C Program s Line 3: { s This opening bracket denotes the start of the program.
  • 22. Simple C Program s Line 4: printf("Hello World From Aboutn"); s Printf is a function from a standard C library that is used to print strings to the standard output, normally your screen. s The compiler links code from these standard libraries to the code you have written to produce the final executable. s The "n" is a special format modifier that tells the printf to put a line feed at the end of the line. s If there were another printf in this program, its string would print on the next line.
  • 23. Simple C Program s Line 5: } s This closing bracket denotes the end of the program.
  • 24. Escape Sequence s n new line s t tab s r carriage return s a alert s backslash s ” double quote
  • 25. Memory concepts s Every variable has a name, type and value s Variable names correspond to locations in computer memory s New value over-writes the previous value– “Destructive read-in” s 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 s 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 s Checking falsity or truth of a statement s Equality operators have lower precedence than relational operators s Relational operators have same precedence s Both associate from left to right
  • 31. Decision Making s Equality operators • == • != s 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 s = s += s -= s *= s /= s %=
  • 34. Increment/ decrement operators s ++ ++a s ++ a++ s -- --a s -- a--
  • 35. Increment/ decrement operators main() { int c; c = 5; 5 printf(“%dn”, c); 5 printf(“%dn”, c++); 6 printf(“%dnn”, c); c = 5; printf(“%dn”, c); 5 6 printf(“%dn”, ++c); 6 printf(“%dn”, c); return 0; }
  • 36. Thank You s Thank You

Notes de l'éditeur

  1. Typeless – no datatypes. Every data item occupied 1 word in memory.