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
Introduction to C Programming
What C is, where it runs today, and your first compiled program, with real gcc output showing sizeof, memory addresses and exit codes.
Setting Up a C Development Environment
Install GCC, configure VS Code, and learn to compile and run C programs with Makefiles.
Variables and Storage Classes in C
Declare and initialize C variables, then see scope and the storage classes auto, static, extern and register in real compiled examples.
Data Types in C
Explore C's built-in data types including integers, floating-point numbers, characters, and how to use sizeof and type limits.
Operators in C
C arithmetic, bitwise, shift, logical and ternary operators with real output, including negative modulo and the precedence bugs -Wall catches.
Control Flow in C
C if/else, switch, for, while and do-while loops, break, continue and goto, with real output showing dangling-else and fall-through bugs.
Functions in C
C function prototypes, pass-by-value, output parameters, recursion, static, inline and variadic functions, all shown with real gcc output.
Command-Line Arguments in C
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.
Arrays in C
C arrays in practice: initialization, bounds bugs caught by AddressSanitizer, decay to pointers, 2D and variable-length arrays, and qsort.
Strings in C
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
Pointers in C
Learn C pointers by running them: addresses, pointer arithmetic, pointer-to-pointer, const and void pointers, and function pointer callbacks.
Memory Management in C
Learn malloc, calloc, realloc, and free, understand heap vs stack, detect memory leaks with Valgrind, and avoid buffer overflows.
Structs in C
C structs with real output: designated initializers, typedef, pointers and the arrow operator, padding measured with offsetof, and bit fields.
Unions and Enums in C
C unions and enums in practice: shared memory layout, tagged unions, reading float bits, enum values, and how -Wswitch catches missing cases.
File I/O in C
C file I/O with fopen, fgets, fprintf, fread and fwrite: reading text and CSV, writing binary headers, seeking, and checking every error.
The C Preprocessor
The C preprocessor in practice: #include, #define, macro pitfalls seen through gcc -E, # and ##, conditional compilation and include guards.
Compound Literals and Generic Selection in C
Create anonymous structs and arrays with compound literals, and dispatch on a value's type at compile time with C11's _Generic.
Error Handling in C
Handle errors in C with return codes, errno, perror and strerror, assert vs validation, goto cleanup paths, and the traps of setjmp/longjmp.
Linked Lists in C
Build singly, doubly and circular linked lists in C, with insertion, deletion and reversal verified by AddressSanitizer for leaks and misuse.
Data Structures in C
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.
Makefiles for C Projects
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
Concurrency with pthreads in C
POSIX threads in C: create and join threads, see a real race condition, fix it with mutexes or atomics, and use condition variables.
System Programming in C
Unix system programming in C: fork and exec, exit statuses, signals, pipes, mmap and a TCP round trip, all run for real on Linux.
C Secure Coding: Buffer Overflows, Sanitizers, and Safe Functions
Catch C memory bugs before they ship: AddressSanitizer, _FORTIFY_SOURCE, stack canaries, -Wformat-security, and safe snprintf, fgets and overflow checks.
C Interview Preparation: Top 30 Questions
Master the top 30 C interview questions with detailed answers and working code examples.