You are previewing C Programming Essentials.
O'Reilly logo
C Programming Essentials

Book Description

The book demonstrates key techniques that make C effective and focuses on fundamental concepts for mastery. An introduction to C99 is also provided.

Table of Contents

  1. Copyright
    1. Dedication
  2. Preface
    1. Why Another New Book on C?
    2. Relevance of C in Today’s World
    3. Features of This Book
    4. Target Audience for This Book
    5. Acknowledgements
  3. 1. Introduction
    1. 1.1. Software
    2. 1.2. Systems Software
      1. 1.2.1. Operating Systems
      2. 1.2.2. Other System Software
    3. 1.3. Application Software
    4. 1.4. Program Development Process
    5. 1.5. Algorithms
    6. 1.6. Analysis of Algorithms
    7. 1.7. Flowcharts
    8. 1.8. Programming Language Classifications
      1. 1.8.1. Assembly Language
      2. 1.8.2. High-level Languages
    9. 1.9. Programming Techniques
      1. 1.9.1. Bottom-up Design
      2. 1.9.2. Top-down Design
      3. 1.9.3. Structured Programming
      4. 1.9.4. Modular Design
    10. 1.10. Structured Programming Constructs
    11. 1.11. History of C Language
    12. 1.12. C Language Overview
    13. Summary
    14. New Terminology Checklist
    15. Exercises
  4. 2. The Foundation of C
    1. 2.1. Memory and Storage
    2. 2.2. C Character Set
    3. 2.3. C Keywords
    4. 2.4. Whitespaces in C
    5. 2.5. Data Types
      1. 2.5.1. Basic Data Types in C
        1. char
        2. int
        3. float
        4. double
      2. 2.5.2. Basic Data Types with Type Modifiers
      3. 2.5.3. Restrictions on Use of Type Modifiers
    6. 2.6. C Constants
      1. 2.6.1. More on Primary Constants
        1. Integer constants
        2. Real constants
        3. Character constants
      2. 2.6.2. String Constants
    7. 2.7. Variables
    8. 2.8. A Peek at Functions
    9. 2.9. Useful Identifier-Naming Conventions
    10. 2.10. Type-Declaration Statements
    11. 2.11. Operators
      1. 2.11.1. Arithmetic Operators
      2. 2.11.2. Assignment Operator
      3. 2.11.3. Increment and Decrement Operators
      4. 2.11.4. Modulus Division Operator
      5. 2.11.5. Shorthand Operators
      6. 2.11.6. Relational and Logical Operators
      7. 2.11.7. Bitwise Operators
      8. 2.11.8. Ternary Conditional Operator
      9. 2.11.9. sizeof Operator
    12. 2.12. Operator Precedence
    13. 2.13. Type Conversion in Expressions
    14. 2.14. Type Conversion in Assignments
    15. 2.15. Type Casting
    16. 2.16. Comments
    17. 2.17. Functions Revisited
    18. 2.18. Putting It Together (First C Program)
    19. 2.19. Some Standard Library I/O Functions
      1. 2.19.1. The printf Library Function
      2. 2.19.2. The scanf Library Function
      3. 2.19.3. The getchar Library Function
      4. 2.19.4. The putchar Library Function
    20. 2.20. Scope of Identifiers
    21. 2.21. Storage Classes
      1. 2.21.1. Automatic Storage Class
      2. 2.21.2. Register Storage Class
      3. 2.21.3. Static Storage Class
      4. 2.21.4. External Storage Class
    22. 2.22. Storage Type Qualifiers
      1. 2.22.1. const
      2. 2.22.2. volatile
    23. Summary
    24. New Terminology Checklist
    25. Exercises
  5. 3. Control
    1. 3.1. The if Statement
      1. 3.1.1. First Form (if Statement)
      2. 3.1.2. Second Form (if–else Statement)
      3. 3.1.3. Extended Form (Nested if Statements)
    2. 3.2. The switch Statement
    3. 3.3. The for Statement
      1. 3.3.1. The Comma Operator
    4. 3.4. The while Statement
    5. 3.5. The do-while Statement
    6. 3.6. The break and continue Statements
    7. 3.7. The Infamous goto
    8. Summary
    9. New Terminology Checklist
    10. Exercises
  6. 4. Functions and Recursion
    1. 4.1. Introduction
    2. 4.2. Function Arguments
    3. 4.3. The return Statement Revisited
    4. 4.4. Call-By-Value
    5. 4.5. Stacks in Function Calls
    6. 4.6. Recursion
    7. 4.7. Towers of Hanoi—Case Study of Recursion
    8. 4.8. Efficiency Considerations for Use of Functions
    9. Summary
    10. New Terminology Checklist
    11. Exercises
  7. 5. Arrays
    1. 5.1. Need for Arrays
    2. 5.2. Single-Dimensional Arrays
    3. 5.3. Single-Dimensional Array Initialization
    4. 5.4. Multi-Dimensional Arrays
    5. 5.5. Matrices
      1. 5.5.1. Matrix Addition
      2. 5.5.2. Matrix Multiplication
    6. 5.6. Row-Major and Column-Major Order
    7. 5.7. Single-Dimensional Character Arrays (Strings)
    8. 5.8. Initialization of Strings
    9. 5.9. gets( ) and puts( )
    10. 5.10. sscanf( ) and sprintf( )
    11. 5.11. String Functions
      1. 5.11.1. strlen
      2. 5.11.2. strcmp and strncmp
      3. 5.11.3. strcat and strncat
      4. 5.11.4. strcpy and strncpy
    12. 5.12. Two-Dimensional Character Arrays
    13. Summary
    14. New Terminology Checklist
    15. Exercises
  8. 6. Pointers
    1. 6.1. Defining a Pointer
    2. 6.2. Scalars for Pointers
    3. 6.3. Pointer Assignments and Expressions
    4. 6.4. Pointer Comparison
    5. 6.5. Passing Pointers to Functions
    6. 6.6. Pointers and Arrays—Pointer Arithmetic
      1. 6.6.1. Two Instances of Pointer Usage
    7. 6.7. Pointers and Two-Dimensional Arrays
    8. 6.8. Arrays of Pointers
    9. 6.9. Pointers to Pointers
    10. 6.10. Pointers to Functions
    11. 6.11. Command-Line Arguments
    12. 6.12. Other Pointer Issues
    13. Summary
    14. New Terminology Checklist
    15. Exercises
  9. 7. User-Defined Data Types
    1. 7.1. Structures
    2. 7.2. Declaring a Structure
    3. 7.3. Defining a Structure Variable
    4. 7.4. Initializing and Referencing Structure Members
    5. 7.5. Nesting of Structures
    6. 7.6. Operations on Structures
    7. 7.7. Pointers to Structures
    8. 7.8. Structures and Functions
    9. 7.9. Arrays of Structures
    10. 7.10. Self-Referential Structures
    11. 7.11. Unions
    12. 7.12. Enumerated Data Types
    13. 7.13. Typedef
    14. 7.14. Bit Fields
    15. Summary
    16. New Terminology Checklist
    17. Exercises
  10. 8. File Access and Processing
    1. 8.1. Introduction
    2. 8.2. Opening and Closing a Disc File
    3. 8.3. Character Input/Output
    4. 8.4. Error-Handling
    5. 8.5. Reading and Writing a File in Convenient Chunks
    6. 8.6. File Positioning
    7. Summary
    8. New Terminology Checklist
    9. Exercises
  11. 9. The C Preprocessor
    1. 9.1. Macro Substitution
    2. 9.2. File Inclusion
    3. 9.3. Conditional Compilation
    4. 9.4. Additional Directives
    5. 9.5. Predefined Preprocessor Identifiers
    6. 9.6. ANSI Standard Header files
    7. Summary
    8. New Terminology Checklist
    9. Exercises
  12. A. Common Errors in C
    1. A.1. Types of Errors
      1. Programming Errors
      2. Compile Errors
      3. Link Error
      4. Execution Error
      5. Logical Errors
    2. A.2. Common Instances of Errors
      1. Remember to start and end comments correctly
      2. The assignment operator ‘=’ is often mistaken for the test operator ‘==’
      3. Errors with missing parenthesis
      4. Use of operators may have side effects
      5. Non-terminated comment
      6. Accidental assignment/accidental booleans
      7. Switch statement
      8. Scanf errors
      9. Size of arrays
      10. Integer division
      11. Loop errors
      12. Prototype
      13. Remember brackets with pointers and increment/decrement operators
      14. Errors caused by using a pointer as argument to a function
      15. Non-initialized pointers
      16. String- and character-constant confusions
      17. Comparing strings with relational operators
      18. Strings without NULL terminator
      19. Not leaving room for the NULL terminator
      20. Input/Output errors
      21. EOF
      22. Leaving characters in the input buffer
      23. Returning local array
  13. B. More on Bitwise Operators in C
    1. B.1. What, Why, and When?
    2. B.2. Bitwise Operators in Use
  14. C. Some Useful Functions from stdlib.h
  15. D. Creating Static Library with gcc
  16. E. C99—A Brief Introduction
    1. E.1. C99 Outlines
    2. E.2. Some Features Removed In C99
    3. E.3. New Additions In C99
      1. Keywords
      2. Features
    4. E.4. Updation to C99 Standard
    5. E.5. New Keywords
      1. Inline
      2. Restrict
    6. E.6. New Types
      1. Bool
      2. Complex and _Imaginary
      3. Long Long Int
    7. E.7. New Features In C99
      1. Single-line Comments
      2. Variable Declaration Within for Loop
      3. Variable-sized Arrays
      4. Declaration of Variable Within Code
      5. Compound Literals
      6. Flexible-sized Arrays
      7. Designated Initializer
  17. F. Practice Problems
    1. F.1. Section – I
      1. Short Questions
    2. F.2. Section – II
      1. Programming Exercises
    3. Solutions for Programming Exercises