C Programming.1.pdf - C Programming en.wikibooks.org On the 28th of April 2012 the contents of the English as well as German Wikibooks and Wikipedia

C Programming.1.pdf - C Programming en.wikibooks.org On the...

This preview shows page 1 - 5 out of 285 pages.

C Programming en.wikibooks.org
Image of page 1
November 24, 2013 On the 28th of April 2012 the contents of the English as well as German Wikibooks and Wikipedia projects were licensed under Creative Commons Attribution-ShareAlike 3.0 Unported license. A URI to this license is given in the list of figures on page 273. If this document is a derived work from the contents of one of these projects and the content was still licensed by the project under this license at the time of derivation this document has to be licensed under the same, a similar or a compatible license, as stated in section 4b of the license. The list of contributors is included in chapter Contributors on page 265. The licenses GPL, LGPL and GFDL are included in chapter Licenses on page 277, since this book and/or parts of it may or may not be licensed under one or more of these licenses, and thus require inclusion of these licenses. The licenses of the figures are given in the list of figures on page 273. This PDF was generated by the L A T E X typesetting software. The L A T E X source code is included as an attachment ( source.7z.txt ) in this PDF file. To extract the source from the PDF file, you can use the pdfdetach tool including in the poppler suite, or the . pdflabs.com/tools/pdftk-the-pdf-toolkit/ utility. Some PDF viewers may also let you save the attachment to a file. After extracting it from the PDF file you have to rename it to source.7z . To uncompress the resulting archive we recommend the use of . The L A T E X source itself was generated by a program written by Dirk Hünniger, which is freely available under an open source license from .
Image of page 2
Contents 1 Why learn C? 3 2 History 7 3 What you need before you can learn 9 3.1 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.2 Footnotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4 Using a Compiler 13 5 A taste of C 19 6 Intro exercise 21 6.1 Introductory Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 7 Beginning C 25 8 Preliminaries 27 8.1 Basic Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 8.2 Block Structure, Statements, Whitespace, and Scope . . . . . . . . . . . . 27 8.3 Basics of Using Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 8.4 The Standard Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 9 Compiling 31 9.1 Preprocessor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 9.2 Syntax Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 9.3 Object Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 9.4 Linking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 9.5 Automation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 10 Structure and style 35 10.1 C Structure and Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 10.2 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 10.3 Line Breaks and Indentation . . . . . . . . . . . . . . . . . . . . . . . . . . 36 10.4 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 10.5 Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 11 Error handling 43 11.1 Preventing divide by zero errors . . . . . . . . . . . . . . . . . . . . . . . . 44 11.2 Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 11.3 setjmp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 III
Image of page 3
Contents 12 Variables 47 12.1 Declaring, Initializing, and Assigning Variables . . . . . . . . . . . . . . . . 47 12.2 Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 12.3 The Four Basic Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . 49 12.4 sizeof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 12.5 Data type modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 12.6 const qualifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 12.7 Magic numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 12.8 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 12.9 Other Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 13 Simple Input and Output 59 13.1 Output using printf() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 13.2 Other output methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 13.3 Input using scanf() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 13.4 Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 14 Simple math 65 14.1 Operators and Assignments . . . . . . . . . . . . . . . . . . . . . . . . . . 65 15 Further math 73 15.1 Trigonometric functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 15.2 Hyperbolic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 15.3 Exponential and logarithmic functions . . . . . . . . . . . . . . . . . . . . 75 15.4 Power functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 15.5 Nearest integer, absolute value, and remainder functions . . . . . . . . . . 78 15.6 Error and gamma functions . . . . . . . . . . . . . . . . . . . . . . . . . . 80 15.7 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 16 Control 83 16.1 Conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 16.2 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 16.3 One last thing: goto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 16.4 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 16.5
Image of page 4
Image of page 5

You've reached the end of your free preview.

Want to read all 285 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture