Introduction to C Programming   Introduction
Bookss   “The Waite Group’s Turbo C Programming for PC”,    Robert Lafore, SAMSs   “C How to Program”, H.M. Deitel, P.J. D...
What is C?s   C    s   A language written by Brian Kernighan        and Dennis Ritchie. This was to be the        language...
Why use C?    s   Mainly because it produces code that runs nearly as fast        as code written in assembly language. So...
Historys   In 1972 Dennis Ritchie at Bell Labs writes C and in    1978 the publication of The C Programming Language    by...
Why C Still Useful?s   C provides:    x   Efficiency, high performance and high quality s/ws    x   flexibility and power ...
Software Development Methods   Requirement Specification    – Problem Definitions   Analysis    – Refine, Generalize, Deco...
Development with Cs   Four stages     Editing: Writing the source code by using some IDE or editor     Preprocessing or ...
Programming languagess   Various programming languagess   Some understandable directly by computerss   Others require “tra...
Programming languagess   Assembly Language    – English like abbreviations    – Translators programs called “Assemblers” t...
Programming languagess   High-level languages    – To speed up programming even further    – Single statements for accompl...
History of Cs   Evolved from two previous languages     – BCPL , Bs   BCPL (Basic Combined Programming Language) used    f...
History of Cs   Hardware independents   Programs portable to most computerss   Dialects of C    – Common C    – ANSI C    ...
C Standard Librarys   Two parts to learning the “C” world     – Learn C itself     – Take advantage of rich collection of ...
Basics of C Environments   C systems consist of 3 parts     – Environment     – Language     – C Standard Librarys   Devel...
Basics of C Environment                              Program edited inPhase 1    Editor      Disk   Editor and stored     ...
Basics of C Environment                    Primary memory                                       Puts program inPhase 5   L...
Simple C Program/* A first C Program*/#include <stdio.h>void main(){     printf("Hello World n");}
Simple C Programs   Line 1: #include <stdio.h>s   As part of compilation, the C compiler runs a program    called the C pr...
Simple C Programs   Line 2: void main()s   This statement declares the main function.s   A C program can contain many func...
Simple C Programs   Line 3: {s   This opening bracket denotes the start of the program.
Simple C Programs   Line 4: printf("Hello World From Aboutn");s   Printf is a function from a standard C library that is u...
Simple C Programs   Line 5: }s     This closing bracket denotes the end of the program.
Escape Sequences   n   new lines   t   tabs   r   carriage returns   a   alerts      backslashs   ”   double quote
Memory conceptss   Every variable has a name, type and values   Variable names correspond to locations in computer    memo...
Arithmetic in CC operation          Algebraic CAddition(+)          f+7            f+7Subtraction (-)      p-c            ...
Precedence orders   Highest to lowest       • ()       • *, /, %       • +, -
ExampleAlgebra:           z = pr%q+w/x-yC:           z = p * r % q + w / x – y ;Precedence:                1    2      4  ...
ExampleAlgebra:           a(b+c)+ c(d+e)C:           a * ( b + c ) + c * ( d + e ) ;Precedence:              3    1       ...
Decision Makings   Checking falsity or truth of a statements   Equality operators have lower precedence than    relational...
Decision Makings   Equality operators        • ==        • !=s   Relational operators        •<        •>        • <=     ...
Summary of precedence orderOperator    Associativity    ()       left to right* / %        left to right    + -      left ...
Assignment operatorss   =s   +=s   -=s   *=s   /=s   %=
Increment/ decrement operatorss   ++    ++as   ++    a++s   --    --as   --    a--
Increment/ decrement operatorsmain(){     int c;     c = 5;                              5     printf(“%dn”, c);       5  ...
Thank Yous   Thank You
Upcoming SlideShare
Loading in …5
×

01 c

571 views

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
571
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
17
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Typeless – no datatypes. Every data item occupied 1 word in memory.
  • 01 c

    1. 1. Introduction to C Programming Introduction
    2. 2. Bookss “The Waite Group’s Turbo C Programming for PC”, Robert Lafore, SAMSs “C How to Program”, H.M. Deitel, P.J. Deitel, Prentice Hall
    3. 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" languageIn recent years C has been used as a general-purpose language because of its popularity withprogrammers.
    4. 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 – UtilitiesMainly because of the portability that writing standard C programs canoffer
    5. 5. Historys 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 worlds 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. 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++  Javas 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. 7. Software Development Methods Requirement Specification – Problem Definitions Analysis – Refine, Generalize, Decompose the problem definitions Design – Develop Algorithms Implementation – Write Codes Verification and Testing – Test and Debug the code
    8. 8. Development with Cs 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. 9. Programming languagess Various programming languagess Some understandable directly by computerss 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. 10. Programming languagess 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. 11. Programming languagess 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. 12. History of Cs Evolved from two previous languages – BCPL , Bs BCPL (Basic Combined Programming Language) used for writing OS & compilerss B used for creating early versions of UNIX OSs Both were “typeless” languagess C language evolved from B (Dennis Ritchie – Bell labs) ** Typeless – no datatypes. Every data item occupied 1 word in memory.
    13. 13. History of Cs Hardware independents Programs portable to most computerss Dialects of C – Common C – ANSI C • ANSI/ ISO 9899: 1990 • Called American National Standards Institute ANSI Cs Case-sensitive
    14. 14. C Standard Librarys Two parts to learning the “C” world – Learn C itself – Take advantage of rich collection of existing functions called C Standard Librarys Avoid reinventing the wheels SW reusability
    15. 15. Basics of C Environments C systems consist of 3 parts – Environment – Language – C Standard Librarys Development environment has 6 phases – Edit – Pre-processor – Compile – Link – Load – Execute
    16. 16. Basics of C Environment Program edited inPhase 1 Editor Disk Editor and stored on disk PreprocessorPhase 2 Preprocessor Disk program processes the code Creates object codePhase 3 Compiler Disk and stores on disk Links object codePhase 4 Linker Disk with libraries and stores on disk
    17. 17. Basics of C Environment Primary memory Puts program inPhase 5 Loader memory Primary memory Takes each instructionPhase 6 CPU and executes it storing new data values
    18. 18. Simple C Program/* A first C Program*/#include <stdio.h>void main(){ printf("Hello World n");}
    19. 19. Simple C Programs 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. 20. Simple C Programs 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. 21. Simple C Programs Line 3: {s This opening bracket denotes the start of the program.
    22. 22. Simple C Programs 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. 23. Simple C Programs Line 5: }s This closing bracket denotes the end of the program.
    24. 24. Escape Sequences n new lines t tabs r carriage returns a alerts backslashs ” double quote
    25. 25. Memory conceptss Every variable has a name, type and values Variable names correspond to locations in computer memorys New value over-writes the previous value– “Destructive read-in”s Value reading called “Non-destructive read-out”
    26. 26. Arithmetic in CC operation Algebraic CAddition(+) f+7 f+7Subtraction (-) p-c p-cMultiplication(*) bm b*mDivision(/) x/y, x , x y x/yModulus(%) r mod s r%s
    27. 27. Precedence orders Highest to lowest • () • *, /, % • +, -
    28. 28. ExampleAlgebra: z = pr%q+w/x-yC: z = p * r % q + w / x – y ;Precedence: 1 2 4 3 5
    29. 29. ExampleAlgebra: a(b+c)+ c(d+e)C: a * ( b + c ) + c * ( d + e ) ;Precedence: 3 1 5 4 2
    30. 30. Decision Makings Checking falsity or truth of a statements Equality operators have lower precedence than relational operatorss Relational operators have same precedences Both associate from left to right
    31. 31. Decision Makings Equality operators • == • !=s Relational operators •< •> • <= • >=
    32. 32. Summary of precedence orderOperator Associativity () left to right* / % left to right + - left to right< <= > >= left to right== != left to right = left to right
    33. 33. Assignment operatorss =s +=s -=s *=s /=s %=
    34. 34. Increment/ decrement operatorss ++ ++as ++ a++s -- --as -- a--
    35. 35. Increment/ decrement operatorsmain(){ 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. 36. Thank Yous Thank You

    ×