Leanpub Header

Skip to main content

C Programming

How to Think Like a C Programmer

This book is about thinking clearly in C. It teaches the mental habits behind safe memory use, careful pointer handling, robust error strategies, effective debugging, and clean interface design. It is written for programmers who want to write C code that remains correct, efficient, and understandable over time.

Minimum price

$15.00

$25.00

You pay

$25.00

Author earns

$20.00
$

...Or Buy With Credits!

You can get credits with a paid monthly or annual Reader Membership, or you can buy them here.
PDF
EPUB
About

About

About the Book

C Programming: How to Think Like a C Programmer is a focused guide to the mindset required for writing correct and reliable C programs. It explores memory discipline, pointer safety, error handling, debugging practices, performance awareness, and clean code organization as core principles rather than afterthoughts. This book is written for programmers who want to use C with clarity, confidence, and long-term maintainability across any domain where C is applied.

Author

About the Author

Budi Raharjo

Two decades of expertise in software engineering and technical training.

Contents

Table of Contents

Preface

  1. Part I. First Contact

Chapter 1. Why C Still Matters

  1. C as a Portable Assembly
  2. C and the Shape of Modern Software
  3. What You Can Build with C
  4. The Limits of C — and Why They Matter

Chapter 2. Setting Up the Environment

  1. Choosing a Compiler
  2. Command-Line Compilation
  3. Understanding the Build Process
  4. Your First C Program
  5. A Lightweight IDE for C: Geany
  6. How to Read Compiler Errors

Chapter 3. A First Mental Model

  1. Programs as Memory and Instructions
  2. Variables as Named Memory
  3. Statements as Steps in Time
  4. Part II. Core Language Foundations

Chapter 4. Basic Types and Values

  1. Integer Types and Their Ranges
  2. Floating-Point Reality
  3. Characters and Text
  4. Type Conversion Rules

Chapter 5. Expressions and Operators

  1. Expressions as Computations
  2. The Operator Landscape in C
  3. Increment and Decrement Operators
  4. Operator Precedence and Clarity
  5. Side Effects and Sequence Points
  6. The Ternary Operator (?:)
  7. Writing Predictable Expressions

Chapter 6. Control Flow

  1. Branching with if and switch
  2. Looping with while and for
  3. The do-while Loop
  4. Breaking and Continuing
  5. Structured Thinking in C

Chapter 7. Functions and Program Structure

  1. Functions as Units of Work
  2. Void Functions
  3. Parameters and Return Values
  4. Local Scope and Lifetime
  5. Organizing Multi-File Programs
  6. Part III. Memory and Data Representation

Chapter 8. Arrays and Strings

  1. Contiguous Memory
  2. Indexing and Bounds
  3. Strings as Character Arrays
  4. Common String Operations
  5. Common String Pitfalls

Chapter 9. Pointers and Addresses

  1. Memory Addresses as Values
  2. Pointer Types and Arithmetic
  3. Pointers and Arrays — The Deep Relationship
  4. Reading Pointer Declarations
  5. When and Why to Use Pointers
  6. Common Pointer Pitfalls

Chapter 10. Lifetime and Storage Duration

  1. Automatic Storage
  2. Static Storage
  3. Dynamic Allocation
  4. Why Lifetime Matters

Chapter 11. Dynamic Memory

  1. malloc and free
  2. Ownership of Allocated Memory
  3. Memory Leaks and Dangling Pointers
  4. Patterns for Safe Allocation
  5. Part IV. Structuring Data

Chapter 12. Structures

  1. Grouping Related Data
  2. Defining and Using struct
  3. Structures and Memory Layout
  4. Passing Structures to Functions
  5. Best Practices for Using Structures

Chapter 13. Unions and Bit-Level Representation

  1. Overlapping Storage
  2. When Unions Make Sense
  3. Bit Fields
  4. Low-Level Data Modeling

Chapter 14. Enumerations and Symbolic Meaning

  1. Named Integer Sets
  2. Enums for Readable Code
  3. Enums and Type Safety
  4. Part V. Working with the Outside World

Chapter 15. Input and Output

  1. Standard Streams
  2. Formatted Output
  3. Reading Input Safely
  4. File Streams

Chapter 16. Files and Persistence

  1. Opening and Closing Files
  2. Binary vs Text Files
  3. File Positioning
  4. Practical File Patterns

Chapter 17. The C Standard Library

  1. Headers and Interfaces
  2. String and Memory Utilities
  3. Mathematical Functions
  4. Error Reporting
  5. Part VI. The Preprocessor and Build Model

Chapter 18. The Preprocessor

  1. Macro Expansion Model
  2. Object-like and Function-like Macros
  3. Header Files and Include Guards
  4. When Not to Use Macros

Chapter 19. Separate Compilation

  1. Translation Units
  2. Header Design Principles
  3. Linking Multiple Files
  4. Managing Interfaces
  5. Part VII. Writing Robust C

Chapter 20. Undefined Behavior and Defensive Programming

  1. What Undefined Behavior Really Means
  2. Common Sources of Undefined Behavior
  3. Writing Predictable Programs

Chapter 21. Error Handling Strategies

  1. Return Codes
  2. errno
  3. Designing Error-Conscious APIs

Chapter 22. Testing and Debugging

  1. Using a Debugger
  2. Assertions
  3. Building Small Test Programs
  4. Part VIII. Thinking in C

Chapter 23. Performance and Cost Models

  1. What C Gives You
  2. Constant-Time Thinking
  3. Memory Access Patterns

Chapter 24. Abstraction in a Low-Level Language

  1. Abstraction Without Classes
  2. Opaque Structs
  3. Designing Clean Interfaces

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub