You are previewing The C Programming Language, Second Edition.
O'Reilly logo
The C Programming Language, Second Edition

Book Description

This ebook is the first authorized digital version of Kernighan and Ritchie’s 1988 classic, The C Programming Language (2nd Ed.). One of the best-selling programming books published in the last fifty years, "K&R" has been called everything from the "bible" to "a landmark in computer science" and it has influenced generations of programmers. Available now for all leading ebook platforms, this concise and beautifully written text is a "must-have" reference for every serious programmer’s digital library.

As modestly described by the authors in the Preface to the First Edition, this "is not an introductory programming manual; it assumes some familiarity with basic programming concepts like variables, assignment statements, loops, and functions. Nonetheless, a novice programmer should be able to read along and pick up the language, although access to a more knowledgeable colleague will help."

Table of Contents

  1. Preface to the Digital Edition
  2. Note from the Publisher
  3. Title Page
  4. Copyright Page
  5. Contents
  6. Preface
  7. Preface to the First Edition
  8. Introduction
  9. CHAPTER 1: A Tutorial Introduction
    1. 1.1 Getting Started
    2. 1.2 Variables and Arithmetic Expressions
    3. 1.3 The For Statement
    4. 1.4 Symbolic Constants
    5. 1.5 Character Input and Output
    6. 1.6 Arrays
    7. 1.7 Functions
    8. 1.8 Arguments—Call by Value
    9. 1.9 Character Arrays
    10. 1.10 External Variables and Scope
  10. CHAPTER 2: Types, Operators, and Expressions
    1. 2.1 Variable Names
    2. 2.2 Data Types and Sizes
    3. 2.3 Constants
    4. 2.4 Declarations
    5. 2.5 Arithmetic Operators
    6. 2.6 Relational and Logical Operators
    7. 2.7 Type Conversions
    8. 2.8 Increment and Decrement Operators
    9. 2.9 Bitwise Operators
    10. 2.10 Assignment Operators and Expressions
    11. 2.11 Conditional Expressions
    12. 2.12 Precedence and Order of Evaluation
  11. CHAPTER 3: Control Flow
    1. 3.1 Statements and Blocks
    2. 3.2 If-Else
    3. 3.3 Else-If
    4. 3.4 Switch
    5. 3.5 Loops—While and For
    6. 3.6 Loops—Do-while
    7. 3.7 Break and Continue
    8. 3.8 Goto and Labels
  12. CHAPTER 4: Functions and Program Structure
    1. 4.1 Basics of Functions
    2. 4.2 Functions Returning Non-integers
    3. 4.3 External Variables
    4. 4.4 Scope Rules
    5. 4.5 Header Files
    6. 4.6 Static Variables
    7. 4.7 Register Variables
    8. 4.8 Block Structure
    9. 4.9 Initialization
    10. 4.10 Recursion
    11. 4.11 The C Preprocessor
  13. CHAPTER 5: Pointers and Arrays
    1. 5.1 Pointers and Addresses
    2. 5.2 Pointers and Function Arguments
    3. 5.3 Pointers and Arrays
    4. 5.4 Address Arithmetic
    5. 5.5 Character Pointers and Functions
    6. 5.6 Pointer Arrays; Pointers to Pointers
    7. 5.7 Multi-dimensional Arrays
    8. 5.8 Initialization of Pointer Arrays
    9. 5.9 Pointers vs. Multi-dimensional Arrays
    10. 5.10 Command-line Arguments
    11. 5.11 Pointers to Functions
    12. 5.12 Complicated Declarations
  14. CHAPTER 6: Structures
    1. 6.1 Basics of Structures
    2. 6.2 Structures and Functions
    3. 6.3 Arrays of Structures
    4. 6.4 Pointers to Structures
    5. 6.5 Self-referential Structures
    6. 6.6 Table Lookup
    7. 6.7 Typedef
    8. 6.8 Unions
    9. 6.9 Bit-fields
  15. CHAPTER 7: Input and Output
    1. 7.1 Standard Input and Output
    2. 7.2 Formatted Output—Printf
    3. 7.3 Variable-length Argument Lists
    4. 7.4 Formatted Input—Scanf
    5. 7.5 File Access
    6. 7.6 Error Handling—Stderr and Exit
    7. 7.7 Line Input and Output
    8. 7.8 Miscellaneous Functions
  16. CHAPTER 8: The UNIX System Interface
    1. 8.1 File Descriptors
    2. 8.2 Low Level I/O—Read and Write
    3. 8.3 Open, Creat, Close, Unlink
    4. 8.4 Random Access—Lseek
    5. 8.5 Example—An Implementation of Fopen and Getc
    6. 8.6 Example—Listing Directories
    7. 8.7 Example—A Storage Allocator
  17. APPENDIX A: Reference Manual
    1. A1. Introduction
    2. A2. Lexical Conventions
    3. A3. Syntax Notation
    4. A4. Meaning of Identifiers
    5. A5. Objects and Lvalues
    6. A6. Conversions
    7. A7. Expressions
    8. A8. Declarations
    9. A9. Statements
    10. A10. External Declarations
    11. A11. Scope and Linkage
    12. A12. Preprocessing
    13. A13. Grammar
  18. APPENDIX B: Standard Library
    1. B1. Input and Output: <stdio.h>
    2. B2. Character Class Tests: <ctype.h>
    3. B3. String Functions: <string.h>
    4. B4. Mathematical Functions: <math.h>
    5. B5. Utility Functions: <stdlib.h>
    6. B6. Diagnostics: <assert.h>
    7. B7. Variable Argument Lists: <stdarg.h>
    8. B8. Non-local Jumps: <setjmp.h>
    9. B9. Signals: <signal.h>
    10. B10. Date and Time Functions: <time.h>
    11. B11. Implementation-defined Limits: <limits.h> and <float.h>
  19. APPENDIX C: Summary of Changes
  20. Index