Programming in C, Fourth Edition

Book description

Programming in C will teach you how to write programs in the C programming language. Whether you’re a novice or experienced programmer, this book will provide you with a clear understanding of this language, which is the foundation for many object-oriented programming languages such as C++, Objective-C, C#, and Java.

 

This book teaches C by example, with complete C programs used to illustrate each new concept along the way. Stephen Kochan provides step-by-step explanations for all C functions. You will learn both the language fundamentals and good programming practices. Exercises at the end of each chapter make the book ideally suited for classroom use or for self-instruction.

 

All the features of the C language are covered in this book, including the latest additions added with the C11 standard. Appendixes provide a detailed summary of the language and the standard C library, both organized for quick reference.

 

“Absolutely the best book for anyone starting out programming in C. This is an excellent introductory text with frequent examples and good text.…This is the book I used to learn C–it’s a great book.”

Vinit S. Carpenter, Learn C/C++ Today

Table of contents

  1. Cover Page
  2. About This eBook
  3. Title Page
  4. Copyright Page
  5. Developer’s Library
  6. Dedication
  7. Contents at a Glance
  8. Table of Contents
  9. About the Author
  10. Acknowledgments
  11. We Want to Hear from You!
  12. Reader Services
  13. Introduction
  14. 1 Some Fundamentals
    1. Programming
    2. Higher-Level Languages
    3. Operating Systems
    4. Compiling Programs
    5. Integrated Development Environments
    6. Language Interpreters
  15. 2 Compiling and Running Your First Program
    1. Compiling Your Program
    2. Running Your Program
    3. Understanding Your First Program
    4. Displaying the Values of Variables
    5. Comments
    6. Exercises
  16. 3 Variables, Data Types, and Arithmetic Expressions
    1. Understanding Data Types and Constants
      1. The Integer Type int
      2. The Floating Number Type float
      3. The Extended Precision Type double
      4. The Single Character Type char
      5. The Boolean Data Type _Bool
      6. Type Specifiers: long, long long, short, unsigned, and signed
    2. Working with Variables
    3. Working with Arithmetic Expressions
      1. Integer Arithmetic and the Unary Minus Operator
    4. Combining Operations with Assignment: The Assignment Operators
    5. Types _Complex and _Imaginary
    6. Exercises
  17. 4 Program Looping
    1. Triangular Numbers
    2. The for Statement
      1. Relational Operators
      2. Aligning Output
    3. Program Input
      1. Nested for Loops
      2. for Loop Variants
    4. The while Statement
    5. The do Statement
      1. The break Statement
      2. The continue Statement
    6. Exercises
  18. 5 Making Decisions
    1. The if Statement
      1. The if-else Construct
      2. Compound Relational Tests
      3. Nested if Statements
      4. The else if Construct
    2. The switch Statement
    3. Boolean Variables
    4. The Conditional Operator
    5. Exercises
  19. 6 Working with Arrays
    1. Defining an Array
      1. Using Array Elements as Counters
      2. Generating Fibonacci Numbers
      3. Using an Array to Generate Prime Numbers
    2. Initializing Arrays
    3. Character Arrays
      1. Base Conversion Using Arrays
      2. The const Qualifier
    4. Multidimensional Arrays
    5. Variable Length Arrays
    6. Exercises
  20. 7 Working with Functions
    1. Defining a Function
    2. Arguments and Local Variables
      1. Function Prototype Declaration
      2. Automatic Local Variables
    3. Returning Function Results
    4. Functions Calling Functions Calling...
      1. Declaring Return Types and Argument Types
      2. Checking Function Arguments
    5. Top-Down Programming
    6. Functions and Arrays
      1. Assignment Operators
      2. Sorting Arrays
      3. Multidimensional Arrays
    7. Global Variables
    8. Automatic and Static Variables
    9. Recursive Functions
    10. Exercises
  21. 8 Working with Structures
    1. The Basics of Structures
    2. A Structure for Storing the Date
      1. Using Structures in Expressions
    3. Functions and Structures
      1. A Structure for Storing the Time
    4. Initializing Structures
      1. Compound Literals
    5. Arrays of Structures
    6. Structures Containing Structures
    7. Structures Containing Arrays
    8. Structure Variants
    9. Exercises
  22. 9 Character Strings
    1. Revisiting the Basics of Strings
    2. Arrays of Characters
    3. Variable-Length Character Strings
      1. Initializing and Displaying Character Strings
      2. Testing Two Character Strings for Equality
      3. Inputting Character Strings
      4. Single-Character Input
      5. The Null String
    4. Escape Characters
    5. More on Constant Strings
    6. Character Strings, Structures, and Arrays
      1. A Better Search Method
    7. Character Operations
    8. Exercises
  23. 10 Pointers
    1. Pointers and Indirection
    2. Defining a Pointer Variable
    3. Using Pointers in Expressions
    4. Working with Pointers and Structures
      1. Structures Containing Pointers
      2. Linked Lists
    5. The Keyword const and Pointers
    6. Pointers and Functions
    7. Pointers and Arrays
      1. A Slight Digression About Program Optimization
      2. Is It an Array or Is It a Pointer?
      3. Pointers to Character Strings
      4. Constant Character Strings and Pointers
      5. The Increment and Decrement Operators Revisited
    8. Operations on Pointers
    9. Pointers to Functions
    10. Pointers and Memory Addresses
    11. Exercises
  24. 11 Operations on Bits
    1. The Basics of Bits
    2. Bit Operators
      1. The Bitwise AND Operator
      2. The Bitwise Inclusive-OR Operator
      3. The Bitwise Exclusive-OR Operator
      4. The Ones Complement Operator
      5. The Left Shift Operator
      6. The Right Shift Operator
      7. A Shift Function
      8. Rotating Bits
    3. Bit Fields
    4. Exercises
  25. 12 The Preprocessor
    1. The #define Statement
      1. Program Extendability
      2. Program Portability
      3. More Advanced Types of Definitions
      4. The # Operator
      5. The ## Operator
    2. The #include Statement
      1. System Include Files
    3. Conditional Compilation
      1. The #ifdef, #endif, #else, and #ifndef Statements
      2. The #if and #elif Preprocessor Statements
      3. The #undef Statement
    4. Exercises
  26. 13 Extending Data Types with the Enumerated Data Type, Type Definitions, and Data Type Conversions
    1. Enumerated Data Types
    2. The typedef Statement
    3. Data Type Conversions
      1. Sign Extension
      2. Argument Conversion
    4. Exercises
  27. 14 Working with Larger Programs
    1. Dividing Your Program into Multiple Files
      1. Compiling Multiple Source Files from the Command Line
    2. Communication Between Modules
      1. External Variables
      2. Static Versus Extern Variables and Functions
      3. Using Header Files Effectively
    3. Other Utilities for Working with Larger Programs
      1. The make Utility
      2. The cvs Utility
      3. Unix Utilities: ar, grep, sed, and so on
  28. 15 Input and Output Operations in C
    1. Character I/O: getchar() and putchar()
    2. Formatted I/O: printf() and scanf()
      1. The printf() Function
      2. The scanf() Function
    3. Input and Output Operations with Files
      1. Redirecting I/O to a File
      2. End of File
    4. Special Functions for Working with Files
      1. The fopen Function
      2. The getc() and putc() Functions
      3. The fclose() Function
      4. The feof Function
      5. The fprintf() and fscanf() Functions
      6. The fgets() and fputs() Functions
      7. stdin, stdout, and stderr
      8. The exit() Function
      9. Renaming and Removing Files
    5. Exercises
  29. 16 Miscellaneous and Advanced Features
    1. Miscellaneous Language Statements
      1. The goto Statement
      2. The null Statement
    2. Working with Unions
    3. The Comma Operator
    4. Type Qualifiers
      1. The register Qualifier
      2. The volatile Qualifier
      3. The restrict Qualifier
    5. Command-line Arguments
    6. Dynamic Memory Allocation
      1. The calloc() and malloc() Functions
      2. The sizeof Operator
      3. The free Function
    7. Exercises
  30. 17 Debugging Programs
    1. Debugging with the Preprocessor
    2. Debugging Programs with gdb
      1. Working with Variables
      2. Source File Display
      3. Controlling Program Execution
      4. Getting a Stack Trace
      5. Calling Functions and Setting Arrays and Structures
      6. Getting Help with gdb Commands
      7. Odds and Ends
  31. 18 Object-Oriented Programming
    1. What Is an Object Anyway?
    2. Instances and Methods
    3. Writing a C Program to Work with Fractions
    4. Defining an Objective-C Class to Work with Fractions
    5. Defining a C++ Class to Work with Fractions
    6. Defining a C# Class to Work with Fractions
  32. A C Language Summary
    1. 1.0 Digraphs and Identifiers
    2. 2.0 Comments
    3. 3.0 Constants
    4. 4.0 Data Types and Declarations
    5. 5.0 Expressions
    6. 6.0 Storage Classes and Scope
    7. 7.0 Functions
    8. 8.0 Statements
    9. 9.0 The Preprocessor
  33. B The Standard C Library
    1. Standard Header Files
    2. String Functions
    3. Memory Functions
    4. Character Functions
    5. I/O Functions
    6. In-Memory Format Conversion Functions
    7. String-to-Number Conversion
    8. Dynamic Memory Allocation Functions
    9. Math Functions
    10. General Utility Functions
  34. C Compiling Programs with gcc
    1. General Command Format
    2. Command-Line Options
  35. D Common Programming Mistakes
  36. E Resources
    1. The C Programming Language
    2. C Compilers and Integrated Development Environments
    3. Miscellaneous
  37. Index

Product information

  • Title: Programming in C, Fourth Edition
  • Author(s): Stephen G. Kochan
  • Release date: August 2014
  • Publisher(s): Addison-Wesley Professional
  • ISBN: 9780132781206