C Programming

18 lessons

From zero C to manual memory management, pointers, and the compilation model. No garbage collector, no bounds checking, no safety net — see what the machine actually does.

what you'll learn

  • Pointers from scratch — addresses, dereferencing, pointer arithmetic, and void*
  • Manual memory management — malloc, free, and debugging leaks with valgrind
  • Structs, unions, and enums — building data structures without a runtime
  • The compilation model — preprocessor, compiler, assembler, linker, and what each produces
  • Arrays, strings, and the C standard library — how strings are really just char*
  • Build a real CLI tool — putting it all together into something that compiles and ships

The Basics Without the Safety Net

Hello, C

Your first C program. gcc, compilation vs interpretation, main returns an int to the OS, printf, header files, and why #include is copy-paste not import.

Types, Sizes, and Overflow

int, char, float, double, sizeof. Signed vs unsigned, integer overflow is undefined behavior, and stdint.h fixed-width types.

Control Flow and Functions

if, for, while, switch. Function declarations vs definitions, forward declarations, and why C needs header files.

Arrays and Strings

Arrays are fixed-size stack memory with no bounds checking. Strings are char arrays terminated by a null byte. strlen, strcpy, strcmp — and why they are all dangerous.

The Preprocessor

#include, #define, #ifdef, macros with arguments, include guards, conditional compilation. A text substitution engine that runs before the compiler sees your code.

Pointers and Memory

Pointers

A pointer is an address. & takes the address, * dereferences it. Pointer arithmetic. Why arrays decay to pointers. NULL. Segfaults.

Stack vs Heap

Automatic storage on the stack, malloc/free on the heap. Returning a pointer to a local variable, double free, use-after-free, memory leaks.

Structs and Typedef

Defining structs, dot and arrow operators, struct layout and padding, typedef, opaque types. How Go structs map to C structs.

Dynamic Data Structures

Build a linked list with malloc. Build a dynamic array with realloc. Understand what Go slices and maps hide from you.

The Compilation Model

From Source to Binary

Preprocessing, compilation, assembly, linking. gcc -E, gcc -S, gcc -c, gcc -o. What each stage produces.

Makefiles

make, targets, dependencies, variables, pattern rules. Build a real multi-file project with a real Makefile.

Static and Dynamic Libraries

ar for .a files, gcc -shared for .so files, linking order, ldd, LD_LIBRARY_PATH. What dependency actually means in C.

Writing Real C

File I/O

fopen/fread/fwrite/fclose, buffered vs unbuffered, FILE* vs file descriptors (open/read/write), when to use which.

Error Handling in C

No exceptions, no Result type. Return codes, errno, perror, strerror. Patterns: goto cleanup, early return. What Go improved.

Undefined Behavior

The compiler assumes UB never happens and optimizes accordingly. Signed overflow, null dereference, out-of-bounds, uninitialized variables. Real examples where UB breaks working code.

Building a Project

Capstone: build a CLI log filter. Reads structured log lines from stdin, filters by level and service, outputs matches. Structs, dynamic memory, string parsing, file I/O, Makefile.