Skip to main content
Programming Languages

C Tutorial with Examples.

C programming tutorial for systems work: operating systems, embedded devices, networking and performance-critical software, one runnable program at a time.

Beginner

Start here — no prior experience needed

10 lessons
c beginner
5 min read

What C is, where it runs today, and your first compiled program, with real gcc output showing sizeof, memory addresses and exit codes.

c beginner
5 min read

Install GCC, configure VS Code, and learn to compile and run C programs with Makefiles.

c beginner
5 min read

Declare and initialize C variables, then see scope and the storage classes auto, static, extern and register in real compiled examples.

c beginner
5 min read

Explore C's built-in data types including integers, floating-point numbers, characters, and how to use sizeof and type limits.

c beginner
5 min read

C arithmetic, bitwise, shift, logical and ternary operators with real output, including negative modulo and the precedence bugs -Wall catches.

c beginner
5 min read

C if/else, switch, for, while and do-while loops, break, continue and goto, with real output showing dangling-else and fall-through bugs.

c beginner
5 min read

C function prototypes, pass-by-value, output parameters, recursion, static, inline and variadic functions, all shown with real gcc output.

c beginner
5 min read

Read arguments with argc and argv, parse flags like -v and -n by hand, validate bad input, and read environment variables with getenv in C.

c beginner
5 min read

C arrays in practice: initialization, bounds bugs caught by AddressSanitizer, decay to pointers, 2D and variable-length arrays, and qsort.

c beginner
5 min read

Learn how C strings work as null-terminated char arrays, how to use string.h functions, and how to handle strings safely.

Intermediate

For developers with core concepts down

11 lessons
c intermediate
5 min read

Learn C pointers by running them: addresses, pointer arithmetic, pointer-to-pointer, const and void pointers, and function pointer callbacks.

c intermediate
5 min read

Learn malloc, calloc, realloc, and free, understand heap vs stack, detect memory leaks with Valgrind, and avoid buffer overflows.

c intermediate
5 min read

C structs with real output: designated initializers, typedef, pointers and the arrow operator, padding measured with offsetof, and bit fields.

c intermediate
5 min read

C unions and enums in practice: shared memory layout, tagged unions, reading float bits, enum values, and how -Wswitch catches missing cases.

c intermediate
5 min read

C file I/O with fopen, fgets, fprintf, fread and fwrite: reading text and CSV, writing binary headers, seeking, and checking every error.

c intermediate
5 min read

The C preprocessor in practice: #include, #define, macro pitfalls seen through gcc -E, # and ##, conditional compilation and include guards.

c intermediate
5 min read

Create anonymous structs and arrays with compound literals, and dispatch on a value's type at compile time with C11's _Generic.

c intermediate
5 min read

Handle errors in C with return codes, errno, perror and strerror, assert vs validation, goto cleanup paths, and the traps of setjmp/longjmp.

c intermediate
5 min read

Build singly, doubly and circular linked lists in C, with insertion, deletion and reversal verified by AddressSanitizer for leaks and misuse.

c intermediate
5 min read

Build a stack, a ring-buffer queue, a chained hash table and a binary search tree in C, with real output showing collisions and tree height.

c intermediate
5 min read

Write Makefiles for C projects: rules, variables, pattern rules, automatic header dependencies, .PHONY targets and static libraries, run for real.

Advanced

Production-grade patterns for experienced engineers

4 lessons