The Little Book of C
Version 0.3.2
Content
A 100-step journey to learn C from first principles
- Download PDF - print-ready
- Download EPUB - e-reader friendly
- View LaTex -
.tex
source - Source code (Github) - Markdown source
- Read on GitHub Pages
Chapter 1. Getting Started with C
- What Is C and Why Learn It
- Installing a C Compiler
- Writing Your First C Program
- Understanding
main
and Return Values - Printing with
printf
- Comments and Code Readability
- Variables and Basic Types
- Declaring and Initializing Variables
- Compiling and Running Programs
- Common Beginner Mistakes
Chapter 2. Working with Data
- Integers, Floats, and Characters
- Type Conversions and Casting
- Constants and Literals
- Operators and Expressions
- Arithmetic Operators
- Comparison and Logical Operators
- Operator Precedence
- Reading Input with
scanf
- The
sizeof
Operator - Debugging Type Errors
Chapter 3. Control Flow
- The
if
Statement - The
else
andelse if
Clauses - Nested Conditionals
- The
switch
Statement - The
while
Loop - The
for
Loop - The
do-while
Loop - Breaking and Continuing Loops
- Using
goto
Safely (and Why to Avoid It) - Patterns of Control Flow
Chapter 4. Functions and Scope
- Defining and Calling Functions
- Function Parameters and Return Values
- Local and Global Variables
- Scope and Lifetime
- Header Declarations (
.h
files) - Pass by Value Explained
- Recursion and Base Cases
- Function Prototypes and Order
- Inline Functions
- Organizing Code with Functions
Chapter 5. Arrays and Strings
- Declaring Arrays
- Indexing and Bounds
- Multidimensional Arrays
- Iterating over Arrays
- Strings as Character Arrays
- String Literals and Null Terminators
- Common String Functions (
strlen
,strcpy
,strcmp
) - Inputting Strings
- Arrays vs. Pointers (A Gentle Intro)
- Common Array Pitfalls
Chapter 6. Pointers and Memory
- What Is a Pointer
- The Address-of (
&
) and Dereference (*
) Operators - Pointer Arithmetic
- Arrays and Pointers Revisited
- Function Parameters with Pointers
- Dynamic Memory Allocation with
malloc
- Using
free
Safely - Pointer to Pointer
NULL
and Dangling Pointers- Debugging Memory Errors
Chapter 7. Structures and Modular Design
- Defining
struct
Types - Accessing Structure Members
- Structures and Functions
- Nested Structures
- Arrays of Structures
- Typedefs for Simpler Names
- Enums and Symbolic Constants
- Unions and Shared Memory
- Organizing Code into Modules
- Splitting Code into
.c
and.h
Files
Chapter 8. The Power of the Preprocessor
- What Is the Preprocessor
#include
and Header Guards- Defining Macros with
#define
- Working with Paths and Filenames
- Conditional Compilation (
#if
,#ifdef
) - Function-like Macros
- Debugging with
#error
and#warning
- Built-in Macros (
__FILE__
,__LINE__
) - The Compilation Pipeline (Preprocess → Compile → Link)
- Balancing Macros and Functions
Chapter 9. Files, Tools, and Concurrency
- File I/O Basics:
fopen
,fclose
- Reading and Writing Files
- Working with Binary Files
- Error Handling in File Operations
- Command-Line Arguments
- Using
make
and Makefiles - Debugging with
gdb
- Understanding Linking and Libraries
- Simple Threads with
<threads.h>
- Synchronization and Data Safety
Chapter 10. Putting It All Together
- Mini Project 1: Text Analyzer
- Mini Project 2: Guessing Game
- Mini Project 3: Calculator
- Mini Project 4: File Copy Utility
- Mini Project 5: Simple Logger
- Mini Project 6: Contact Book
- Mini Project 7: Matrix Operations
- Mini Project 8: JSON-like Parser
- Mini Project 9: Mini Shell
- Mini Project 10: Tiny HTTP Server