Page 1 of 376Free preview · 1–5

About this document

A textbook and reference on ANSI C programming, presenting language features through working programs, code dissections, chapter summaries, and exercises. Topics include data types, operators, control flow, functions, arrays, pointers, strings, preprocessing, structures, list processing, file handling, and operating system interfaces. Later chapters address advanced applications and transitions from C to C++ and Java. Appendices cover the standard library, language syntax, differences between ANSI and traditional C, ASCII codes, and operator precedence.

Free preview text

The first 5 pages, shown as text so search engines and readers can find this document.

Page 2

... A Book on C Programming in C Fourth Edition AI Kelley / Ira Pohl University of Caljfornia Santa Cruz TT ADDISON-WESLEY Boston • San Francisco • New York· Toronto • jIy[ontreal London • Munich • Paris • Madrid Capetown • Sydney' Tokyo • Singapore • Mexico Cit:J1

Page 3

Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks, Where those designatious appear in this book, and we were aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. The publisher offers discounts on this book when ordered in quantity for special sales. For more informa- tion, please contact: Pearson Education Corporate Sales Division 201 W. 103rd Street Indianapolis, IN 46290 (800) 428-5331 corpsales@pearsoned.com Visit AW on the Web: www.awl.com/cseng/ Librmy of Congress Cataloging-in-Publication Data Kelley,Al A book on C: programming in C I Al Kelley, Ira Pohl. -4th ed. p. cm. Includes bibliographical references and index ISBN 0-201-18399-4 1. C (Computer program language) 1. Poh!, Ira, II. Title. QA76.73.C15K44 1997 005.13'3--dc21 Copyright © 1998 by Addison-Wesley 97-44551 CIP All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, or other- wise, without the prior consent of the publisher. Printed in the United States of America. Published simultaneously in Canada. Text printed on recycled and acid-free paper. ISBN 0201183994 9 1011121314 MA 04030201 9th Printing November 2001 For our Parents

Page 4

Contents Preface Chapter 0 Starting from Zero 0.1 Why C? 0.2 ANSI C Standard 0.3 From C to C++ 0.4 From C and C++ to Java Chapter 1 An Overview of C 1.1 Programming and Preparation 1.2 Program Output 1.3 Variables, Expressions, and Assignment 1.4 The Use of #defi ne and #i ncl ude 1.5 The Use of pri ntfO and scanfO 1.6 Flow of Control 1.7 Functions Call-by-Value 1.8 Arrays, Strings, and Pointers Arrays Strings Pointers 1.9 Files xvii 1 2 3 3 4 5 5 6 10 1 3 18 21 29 35 36 37 39 42 47

Page 5

viii ., Contents 1.10 Operating System Considerations Writing and Running a C Program Interrupting a Program Chapter 2 Typing an End-of-file Signal Redirection of the Input and the Output Summary Exercises lexical Elements, Operators, and the C System 2.1 Characters and lexical Elements 2.2 Syntax Rules 2.3 Comments 2.4 Keywords 2.5 Identifiers 2.6 Constants 2.7 String Constants 2.8 Operators and Punctuators 2.9 Precedence and Associativity of Operators 2.10 Increment and Decrement Operators 2.11 Assignment Operators 2.12 An Example: Computing Powers of 2 2.13 The C System Chapter 3 The Preprocessor The Standard library Summary Exercises The Fundamental Data Types 3.1 Declarations, Expressions, and Assignment 3.2 The Fundamental Data Types 3.3 Characters and the Data Type char 3.4 The Data Type i nt 3.5 The Integral Types short, long, and unsi gned 3.6 The Floating Types 3.7 The Use of typedef 3.8 The si zeof Operator 3.9 The Use of getcharO and putcharO 3.10 Mathematical Functions The Use of abs 0 and fabs 0 UNIX and the Mathematics library 53 53 56 56 56 58 60 69 70 73 75 77 78 79 80 81 83 85 87 89 91 91 92 96 98 107 107 110 111 116 11 7 119 122 122 124 127 130 130 ., Contents ix 3.11 Conversions and Casts 131 The Integral Promotions 131 The Usual Arithmetic Conversions 131 Casts 133 3.12 Hexadecimal and Octal Constants 134 e13 Summary 137 Exercises 138 Chapter 4 Flow of Control 147 4.1 Relational, Equality, and logical Operators 147 4.2 Relational Operators and Expressions 149 4.3 Equality Operators and Expressions 152 4.4 logical Operators and Expressions 154 Short-circuit Evaluation 157 4.5 The Compound Statement 157 4.6 The Expression and Empty Statement 158 4.7 The if and the i f-el se Statements 159 4.8 The whi 1e Statement 163 4.9 The for Statement 167 4.10 An Example: Boolean Variables 169 4.11 The Comma Operator 171 4.12 The do Statement 172 4.13 An Example: Fibonacci Numbers 174 4.14 The goto Statement 178 4.15 The break and conti nue Statements 179 4.16 The swi tch Statement 181 4.17 The Conditional Operator 182 Summary 184 Exercises 185 Chapter 5 Functions 197 5.1 Function Definition 197 5.2 The return Statement 200 5.3 Function Prototypes 201 Function Prototypes in C++ 202 5.4 An Example: Creating a Table of Powers 203 5.5 Function Declarations from the Compiler's Viewpoint 204 limitations 205 5.6 An Alternate Style for Function Definition Order 206 5.7 Function Invocation and Call-by-Value 207

Page 6

x " Contents 5.8 Developing a Large Program What Constitutes a Large Program? 5.9 Using Assertions 5.10 Scope Rules Parallel and Nested Blocks Using a Block for Debugging 5.11 Storage Classes The Storage Class auto The Storage Class extern The Storage Class reg; ster The Storage Class stat; c 5.12 Static External Variables 5.13 Default Initialization 5.14 Recursion Efficiency Considerations 5.15 An Example: The Towers of Hanoi Summary Exercises Chapter 6 Arrays, Pointers, and Strings 6.1 One-dimensional Arrays 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 6.10 6.11 6.12 Initialization Subscripting Pointers Call-by-Reference The Relationship Between Arrays and Pointers Pointer Arithmetic and Element Size Arrays as Function Arguments An Example: Bubble Sort Dynamic Memory Allocation With call oc 0 and mall oc 0 Offsetting the Pointer An Example: Merge and Merge Sort Strings String-Handling Functions in the Standard Library Multidimensional Arrays Two-dimensional Arrays The Storage Mapping Function Formal Parameter Declarations Three-dimensional Arrays Initialization The Use of typedef 6.13 Arrays of Pointers 209 212 212 213 215 216 216 216 217 219 220 221 223 223 227 228 233 235 245 245 246 247 248 252 253 255 256 257 259 262 263 270 272 277 278 279 279 280 281 282 284 6.14 Arguments to ma; nO 6.15 Ragged Arrays 6.16 Functions as Arguments " Contents Functions as Formal Parameters in Function Prototypes 6.17 An Example: Using Bisection to Find the Root of a Function The Kepler Equation 6.18 Arrays of Pointers to Function 6.19 The Type Qualifiers const and vol at; 1 e Summary Exercises Chapter 7 Bitwise Operators and Enumeration Types 7.1 Bitwise Operators and Expressions Bitwise Complement Two's Complement Bitwise Binary Logical Operators Left and Right Shift Operators 7.2 Masks 7.3 Software Tools: Printing an ; nt Bitwise 7.4 Packing and Unpacking Multibyte Character Constants 7.5 Enumeration Types 7.6 An Example: The Game of Paper, Rock, Scissors Summary Exercises Chapter 8 The Preprocessor 8.1 The Use of #i ncl ude 8.2 The Use of #def; ne 8.3 8.4 8.5 8.6 8.7 8.8 8.9 8.10 8.11 8.12 8.13 Syntactic Sugar Macros with Arguments The Type Definitions and Macros in stddef.h An Example: Sorting with qsortO An Example: Macros with Arguments The Macros in stdio.h and ctype.h Conditional Compilation The Predefined Macros The Operators # and ## The assertO Macro The Use of #error and #pragma Line Numbers xi 290 292 293 296 296 300 302 307 309 311 331 331 333 333 334 335 337 338 341 344 345 348 356 357 365 365 366 367 368 371 372 377 382 384 387 387 388 389 390

Tags

Doxxly editorial guide

A Book on C: Programming in C, Fourth Edition: summary, contents and background

This guide helps you understand the scope of A Book on C: Programming in C, Fourth Edition before or alongside reading the original document. It is based on the catalogue record, credited creator, source, classification and topics shown on this page. It does not replace the original work and does not invent claims about passages that Doxxly cannot verify.

Summary and overview

A Book on C: Programming in C, Fourth Edition is a 376-page documentcredited to Freya H. Quinlan. A textbook and reference on ANSI C programming, presenting language features through working programs, code dissections, chapter summaries, and exercises. Topics include data types, operators, control flow, functions, arrays, pointers, strings, preprocessing, structures, list processing, file handling, and operating system interfaces. Later chapters address advanced applications and transitions from C to C++ and Java. Appendices cover the standard library, language syntax, differences between ANSI and traditional C, ASCII codes, and operator precedence. It appears in the Education & Learning collection, which groups it with other material that readers may use for comparison and further study.

The item can be approached in several ways. A reader looking for a quick orientation can begin with the free five-page preview, inspect the page structure and use the metadata to judge relevance. Someone undertaking deeper research can work through the complete file, search its indexed text, record useful page references and compare its treatment of C programming, ANSI C, Programming textbook, Programming reference, Pointers, Data structures, Systems programming, C++, Java with the related resources linked below.

Rather than reducing the work to a single claim, this page treats it as a source that should be read in context. The title, creator, publication source, licence and format all help explain what kind of evidence it may offer. Readers should distinguish the original author's statements from Doxxly's catalogue description, and should cite the original edition when using the material in academic, professional or published work.

Key topics and reader takeaways

The catalogue connects this document with C programming, ANSI C, Programming textbook, Programming reference, Pointers, Data structures, Systems programming, C++, Java. These terms offer practical entry points rather than a substitute for close reading. Start by identifying the definitions, examples, arguments, tables or visual explanations attached to each topic. Then note where the creator draws connections, makes distinctions or moves from background material to a conclusion, recommendation, calculation or narrative development.

A useful reading method is to separate description from interpretation. First record what the item actually presents: names, headings, figures, formulas, quotations or stated propositions. Next consider why those details matter within the whole work. Finally compare them with another source from the same subject area. This process helps turn a long digital file into evidence that can be evaluated rather than merely skimmed.

Table of contents and reading guide

The following is an editorial content guide based on the verified catalogue topics. It is not represented as the original author's formal table of contents. Use it to organise notes while moving through the 376 pages in the player.

  1. Part 1

    C programming

    Use this section of the reading guide to identify how C programming appears in A Book on C: Programming in C, Fourth Edition, note important terms, and connect the subject to the wider purpose of the work.

  2. Part 2

    ANSI C

    Use this section of the reading guide to identify how ANSI C appears in A Book on C: Programming in C, Fourth Edition, note important terms, and connect the subject to the wider purpose of the work.

  3. Part 3

    Programming textbook

    Use this section of the reading guide to identify how Programming textbook appears in A Book on C: Programming in C, Fourth Edition, note important terms, and connect the subject to the wider purpose of the work.

  4. Part 4

    Programming reference

    Use this section of the reading guide to identify how Programming reference appears in A Book on C: Programming in C, Fourth Edition, note important terms, and connect the subject to the wider purpose of the work.

  5. Part 5

    Pointers

    Use this section of the reading guide to identify how Pointers appears in A Book on C: Programming in C, Fourth Edition, note important terms, and connect the subject to the wider purpose of the work.

  6. Part 6

    Data structures

    Use this section of the reading guide to identify how Data structures appears in A Book on C: Programming in C, Fourth Edition, note important terms, and connect the subject to the wider purpose of the work.

  7. Part 7

    Systems programming

    Use this section of the reading guide to identify how Systems programming appears in A Book on C: Programming in C, Fourth Edition, note important terms, and connect the subject to the wider purpose of the work.

  8. Part 8

    C++

    Use this section of the reading guide to identify how C++ appears in A Book on C: Programming in C, Fourth Edition, note important terms, and connect the subject to the wider purpose of the work.

When a heading in the original differs from this guide, follow the original heading in your citation. Page numbers can also vary between editions. Doxxly's direct page field is useful for navigation, but formal references should include the title, creator, source and edition details available in the file itself.

About Freya H. Quinlan

Doxxly credits Freya H. Quinlan as the author or creator of A Book on C: Programming in C, Fourth Edition. This page does not add an unverified biography, job title or institutional affiliation. The attribution is preserved so readers can distinguish the creator from the hosting library and follow the original record when an external author link is available.

Author context matters because a work reflects a particular purpose, audience and point of view. Before relying on the material, consider what the creator set out to explain, when the source was produced and whether later research or revised guidance should also be consulted. For literature and philosophy, compare translations and editions; for technical material, check whether a newer version has superseded the one shown here.

About the source organisation

The recorded source for this item is karadev.net. Doxxly provides access and discovery tools but does not claim to be the original publisher unless explicitly stated. Source links, creator attribution and the recorded Publicly available file collected for editorial review licence are displayed to help readers assess provenance and permitted use.

Provenance is especially important for reports, standards, presentations and working spreadsheets. Check the original source for amendments, supporting files and current policy. A trustworthy research workflow keeps the source URL with any notes or downloaded copy, verifies important figures against the original, and avoids treating an archived document as automatically current.

Visit karadev.net

How to read and use this document

Begin with the title and opening pages, then use the guide above to decide whether to read sequentially or move to a particular topic. The Doxxly player provides previous and next navigation, a direct page field, zoom steps, fit-to-width and fit-to-page modes, rotation and fullscreen. These controls are useful when a page contains small type, a wide table, an image, a scanned layout or a dense sequence of notes.

The first five pages are open to every visitor. A plan unlocks the complete item and full-document search. Search is best used for distinctive names, technical terms or short phrases; broad words can produce too many possible contexts. When you find a useful passage, read the surrounding pages so that a sentence, chart or formula is not separated from its explanation.

If downloading is enabled, members can obtain the original PDF file. Keep the original format when formulas, slide sequencing, pagination or layout carries meaning. Respect the Publicly available file collected for editorial review terms displayed on this page, and use the rights-report link if you believe the attribution or availability needs review.

Research questions to consider

As you read A Book on C: Programming in C, Fourth Edition, ask which audience the creator addresses, what problem or idea organises the work, what evidence is presented, and which assumptions remain unstated. Note whether important terms are defined consistently and whether examples represent a broader pattern or a narrow case. For quantitative material, record units, time periods, formulas and data sources. For interpretive material, separate the creator's language from your own summary.

A second set of questions concerns relevance today. Which parts remain durable, which depend on their historical or institutional setting, and what would need confirmation from a newer source? Following the tags and the Education & Learning collection can reveal useful comparisons. Agreement between sources can strengthen confidence, while disagreement can point to changing definitions, methods, evidence or priorities.

Finally, decide what you need from the item: background knowledge, a quotation, a worked example, a model, a visual explanation or a starting bibliography. That purpose should guide the depth of reading and the notes you keep. Doxxly helps locate and navigate the source; careful interpretation remains the reader's responsibility.

Explore more Education & Learning resources

Frequently asked questions about A Book on C: Programming in C, Fourth Edition

Practical answers about reading, downloading and understanding this document on Doxxly.

More in Education & Learning