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.
C Programming
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
int, char, float, double, sizeof. Signed vs unsigned, integer overflow is undefined behavior, and stdint.h fixed-width types.
if, for, while, switch. Function declarations vs definitions, forward declarations, and why C needs header files.
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.
#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
A pointer is an address. & takes the address, * dereferences it. Pointer arithmetic. Why arrays decay to pointers. NULL. Segfaults.
Automatic storage on the stack, malloc/free on the heap. Returning a pointer to a local variable, double free, use-after-free, memory leaks.
Defining structs, dot and arrow operators, struct layout and padding, typedef, opaque types. How Go structs map to C structs.
Pointers to Pointers and Function Pointers
char **argv, arrays of strings, passing pointers to modify them, function pointers as callbacks — how C does interfaces.
Build a linked list with malloc. Build a dynamic array with realloc. Understand what Go slices and maps hide from you.
The Compilation Model
Preprocessing, compilation, assembly, linking. gcc -E, gcc -S, gcc -c, gcc -o. What each stage produces.
Header Files and Separate Compilation
.h vs .c, declarations vs definitions, one-definition rule, compiling multiple files, and why large C projects have hundreds of header files.
make, targets, dependencies, variables, pattern rules. Build a real multi-file project with a real Makefile.
ar for .a files, gcc -shared for .so files, linking order, ldd, LD_LIBRARY_PATH. What dependency actually means in C.
Writing Real C
fopen/fread/fwrite/fclose, buffered vs unbuffered, FILE* vs file descriptors (open/read/write), when to use which.
No exceptions, no Result type. Return codes, errno, perror, strerror. Patterns: goto cleanup, early return. What Go improved.
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.
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.