Lessons · C
Learn C step by step: 8 lessons with runnable examples
Each lesson pairs a plain-English explanation with code you can run. Every example was executed through the same sandbox the playground uses before it was published, so what you read has been checked, not just typed.
Lesson 1
Your First C Program
What every C program must contain - the main function, printf and its format specifiers, escape sequences, and what a compiler actually does to your source file before anything runs.
printf · main · compiling · basics · 1 exercise to practise it
Lesson 2
Variables and Types in C
Why every C variable must be given a type up front - int, double and char, what sizeof really measures, the integer division trap, and how overflow behaves differently for signed and unsigned values.
variables · data-types · sizeof · integer-division · overflow · 2 exercises to practise it
Lesson 3
Control Flow in C: if, switch and Loops
How C chooses between paths and repeats work - if and else if, why any nonzero value counts as true, switch and deliberate fall-through, while, do-while and for, and steering a loop with break and continue.
conditionals · loops · switch · control-flow · 3 exercises to practise it
Lesson 4
C Functions: Prototypes, Arguments and Return Values
How to define and call a function in C, why the compiler needs a prototype before the call, what pass by value really means for your variables, and how return values, void and recursion fit together.
functions · prototypes · pass-by-value · scope · recursion
Lesson 5
Arrays and Strings in C
How a C array stores a fixed run of same-typed values, why a string is just a char array with a zero byte on the end, how strlen and the string.h functions use that terminator, and why writing past the end of a buffer is so dangerous.
arrays · strings · char · buffers · string.h · 2 exercises to practise it
Lesson 6
Pointers in C
What a pointer actually holds, how & and * work together, why pointer arithmetic counts elements rather than bytes, how passing a pointer lets a function change its caller's variable, and how to write a working swap.
pointers · memory · swap · pass-by-reference · null
Lesson 7
Dynamic Memory in C: malloc and free
How to ask for memory while a program is running, why every malloc must be checked against NULL and matched by exactly one free, and what leaks, dangling pointers and double frees actually are.
malloc · free · memory · heap · null-checks
Lesson 8
Structs and typedef in C
How to group related values into one type with struct, reach members with the dot and arrow operators, shorten the name with typedef, and build and search an array of structs.
structs · typedef · arrays-of-structs · data-modelling · 1 exercise to practise it
Reading is half of it
The C exercises are where you write the code these lessons describe, one idea at a time, with the output checked for you. The playground is for trying any example on this page with your own numbers.