Transcription of The C Book - GBdirect
1 The C Book1 Mike BanahanDeclan BradyMark DoranJanuary 19911 Conversion to LaTeX by Ward van Wanrooij. Any layout issues are caused bymy conversion script and do not reflect on the authors. Also available on-line This Book ..1 The Success of C ..2 Standards ..4 Hosted and Free-Standing Environments ..5 Typographical conventions ..6 Order of topics ..6 Example programs ..7 Deference to Higher Authority ..7 Address for the Standard ..71 An Introduction to The form of a C program .. Functions .. A description of Example .. was in it .. and comment .. statements .. statements .. declaration and definition .. main function .. statement .. while statement .. The return statement .. Summary .. Progress so far .. Some more programs .. program to find prime numbers.
2 Division operators .. example performing input .. arrays .. Terminology .. Summary .. Exercises .. 282 Variables and Some fundamentals .. The alphabet of C .. Alphabet .. Characters .. The Textual Structure of Programs .. Layout .. phases .. Keywords and identifiers .. Declaration of variables .. Real types .. of real arithmatic .. real numbers .. Integral types .. integers .. variables .. complicated types .. of integral types .. the integral types .. Expressions and arithmetic .. promotions .. and unsigned integers .. and integral .. usual arithmetic conversions .. characters .. multiplicative operators .. operators .. bitwise operators.
3 Assignment operators .. and decrement operators .. and grouping .. Effects .. Constants .. constants .. constants .. Summary .. Exercises .. 793 Control of Flow and Logical The Task ahead .. expressions and Relational Operators .. Control of flow .. if statement .. while and do statements .. hints .. for statement .. brief pause .. switch statement .. major restriction .. Constant Expression .. break statement .. continue statement .. and labels .. More logical expressions .. Strange operators .. ?: operator .. comma operator .. Summary .. Exercises .. 100ivCONTENTS4 Changes .. The type of functions .. functions .. return statement .. to functions.
4 Prototypes .. Conversions .. definitions .. statements and declarations .. Recursion and argument passing .. by value .. by reference .. Linkage .. of scope .. static .. Summary .. Exercises .. 1295 Arrays and Opening shots .. why is this important? .. of the Standard .. Arrays .. arrays .. Pointers .. pointers .. and pointers .. types .. arithmetic .. , null and dubious pointers .. Character handling .. and increment operators .. pointers .. Sizeof and storage allocation .. sizeof can t do .. type of sizeof .. Pointers to functions .. Expressions involving pointers .. expressions .. operator .. Summary .. Exercises .. 1726 Structured Data History .. Structures .. and structures.
5 Lists and other structures .. Unions .. Bitfields .. Enums .. Qualifiers and derived types .. Initialization .. expressions .. initialization .. Summary .. Exercises .. 2047 The Effect of the Standard .. How the preprocessor works .. Directives .. null directive .. # define .. substitution .. pasting .. # undef .. # include .. names .. #line .. compilation .. #pragma .. #error .. Summary .. Exercises .. 2228 Specialized Areas of Government Health Warning .. Declarations, Definitions and Accessibility .. class specifiers .. and definitions .. use of linkage and definitions .. Typedef .. Const and volatile .. Operations .. Sequence points .. Summary .. 2469 Introduction.
6 And standard types .. set and cultural dependencies .. Header .. Header .. Diagnostics .. Character handling .. Localization .. setlocale function .. localeconv function .. Limits .. Mathematical functions .. Non-local jumps .. Signal handling .. Variable numbers of arguments .. Input and output .. Introduction .. The I/O model .. Text streams .. Binary streams .. Other streams .. The header file .. Opening, closing and buffering of streams .. Opening .. Closing .. Buffering .. Direct file manipulation .. Opening named files .. Freopen .. Closing files .. Setbuf, setvbuf .. Fflush .. Formatted I/O .. Output: the printf family .. Input: the scanf family .. Character I/O.
7 Character input .. Character output .. String output .. String input .. Unformatted I/O .. Random access functions .. Error handling .. General Utilities .. String conversion functions .. Random number generation .. Memory allocation .. Communication with the environment .. Searching and sorting .. Integer arithmetic functions .. Functions using multibyte characters .. String handling .. Copying .. String and byte comparison .. Character and string searching functions .. Miscellaneous functions .. Date and time .. Summary .. 30310 Complete Programs in Putting it all together .. Arguments to main .. Interpreting program arguments .. A pattern matching program .. A more ambitious example .. Afterword .. 331 Answers to Exercises333 Chapter 1.
8 333 Chapter 2 .. 337 Chapter 3 .. 341 Chapter 4 .. 342 Chapter 5 .. 346 Chapter 6 .. 348 Chapter 7 .. 349 CONTENTS1 PrefaceAbout This BookThis book was written with two groups of readers in mind. Whether youare new to C and want to learn it, or already know the older version of thelanguage but want to find out more about the new standard, we hope thatyou will find what follows both instructive and at times entertaining is not a tutorial introduction to programming. The book is designedfor programmers who already have some experience of using a modern high-level procedural programming language. As we explain later, C isn t reallyappropriate for complete beginners though many have managed to use it so the book will assume that its readers have already done battle with thenotions of statements, variables, conditional execution, arrays, procedures (orsubroutines) and so on.
9 Instead of wasting your time by ploughing throughtedious descriptions of how to add two numbers together and explaining thatthe symbol for multiplication is*, the book concentrates on the things thatare special to C. In particular, it s thewaythat C is used which is who already know C will be interested in the new Standard and howit affects existing C programs. The effect on existing programs might notat first seem to be important to newcomers, but in fact the old and newversions of the languagearean issue for the beginner too. For some yearsafter the approval of the Standard, programmers will have to live in a worldwhere they can easily encounter a mixture of both the new and the oldlanguage, depending on the age of the programs that they are working that reason, the book highlights where the old and new features differsignificantly.
10 Some of the old features are no ornament to the languageand are well worth avoiding; the Standard goes so far as to consider themobsolescent and recommends that they should not be used. For that reasonthey are not described in detail, but only far enough to allow a reader tounderstand what they mean. Anybody who intends towriteprograms usingthese old-style features should be reading a different is the second edition of the book, which has been revised to refer to the2 CONTENTS final, approved version of the Standard. The first edition of the book wasbased on a draft of the Standard which did contain some differences fromthe draft that was eventually approved. During the revision we have takenthe opportunity to include more summary material and an extra chapterillustrating the use of C and the Standard Library to solve a number of Success of CC is a remarkable language.