Learn C – all lessons
18 lessons from beginner to advanced, building on each other and with code examples.
Hello World, main & the Compiler
Your first C program, its parts and the path from source code to an executable file.
Variables, Data Types & Arithmetic
int, double, char, bool, sizeof, constants and the pitfalls of integer division.
Input and Output: printf, scanf, fgets
Formatted output and safe keyboard input.
Conditions: if, switch & Operators
Branching, comparisons, logical operators and the ternary operator.
Loops: for, while, do-while
Repetition, exit conditions, break/continue and nested loops.
Functions, Scope & Recursion
Defining and declaring functions, call by value, static variables and recursion.
Arrays
Fixed-size arrays: indexing, initialization, passing to functions and multidimensional arrays.
Pointers: Addresses & Dereferencing
What a pointer is, call by reference, pointer arithmetic and the relationship with arrays.
Strings as char Arrays
Null-terminated strings, string.h, safe copy and format functions.
structs, typedef, enum & union
Building your own data types: structures, enumerations, variants and access via pointers.
Dynamic Memory: malloc & free
Requesting, resizing and releasing memory at runtime – and avoiding typical mistakes.
Files & Error Handling
Reading and writing files with stdio, checking return codes, errno and cleaning up with goto.
Preprocessor, Headers & Multiple Files
#define, macros and their pitfalls, include guards, splitting into .h/.c and a Makefile.
Function Pointers & Callbacks
Functions as values: callbacks, qsort and dispatch tables.
Data Structures: List & Stack
Linked list with pointer to pointer, array-based stack and ownership rules for memory.
Bit Operations & Fixed-Width Integer Types
Setting, clearing and testing bits; packing flags and color values; stdint.h.
Memory Layout, Padding & Qualifiers
Stack, heap and static memory; struct alignment; const, volatile and restrict.
Undefined Behavior, Security & Debugging
Recognizing and avoiding buffer overflows and other pitfalls, and tracking them down with sanitizers, Valgrind and gdb.