Structured Programming
A complete introduction to C17: program construction, expressions, control flow, functions, arrays, strings, pointers, memory, files, modularity, testing, and debugging.
A program is not finished when it merely produces the expected output once. It should express its intent clearly, handle valid and invalid input deliberately, respect the rules of the language, and remain understandable when its author returns months later.
This course develops those habits using ISO C17. It begins with the journey from source text to an executable program, then builds through data, expressions, decisions, repetition, and functions. The later chapters explain arrays, strings, pointers, records, dynamic storage, recursion, files, separate compilation, testing, and debugging. Examples are intentionally small enough to trace by hand but complete enough to compile and modify.
Use a conforming compiler with strong diagnostics while studying:
cc -std=c17 -Wall -Wextra -Wpedantic -Wconversion program.c -o program
Warnings are evidence to investigate, not messages to silence reflexively. The course also distinguishes portable C from implementation-specific behaviour and calls out undefined behaviour wherever it matters.
The explanations move between three views of the same program: source-level intent, exact state changes during execution, and the implementation contract that makes those changes valid. Complete examples can be compiled as written; trace tables and memory sketches make intermediate state visible; boundary cases show where an apparently reasonable program stops being correct. Interactive experiments appear where changing one value or advancing one step reveals a concept more clearly than another static example.
Do not treat a successful run as the end of an example. Predict its result first, compile with diagnostics, trace the objects that control the next step, and then change a boundary: zero, one, the final valid index, the first invalid value, allocation failure, end-of-file, or an unexpected token. The deeper questions—what invariant survived, which operation owned a resource, what remains unchanged after failure, and which behaviour C actually guarantees—are the same questions used in production reviews and competitive debugging.
The course teaches the language and disciplined program construction. Data-structure design and algorithm analysis belong to the companion courses; examples here use only the simplest structures and procedures needed to illuminate C itself.
Outline
Start →- 01Program BasicsToolchain stages, program anatomy, lexical elements, command-line arguments, and coding style.
- 02Data TypesBasic types, type modifiers, variables, constants, conversions, and type limits.
- 03OperatorsArithmetic, relational, logical, assignment, increment, bitwise, conditional, and size operators, plus precedence, associativity, and expression evaluation.
- 04Input/OutputStandard streams, formatted input and output, character I/O, line input, string parsing, and numeric conversion.
- 05Control FlowConditional and selection statements, loop forms, loop control, nested loops, control tracing, and termination conditions.
- 06FunctionsFunction declarations, definitions, calls, parameters, return values, pass-by-value, scope, storage duration, decomposition, and side effects.
- 07ArraysArray declaration, initialization, indexing, traversal, updates, multidimensional arrays, parameters, variable-length arrays, and boundary safety.
- 08StringsCharacter arrays, null termination, string input and output, copying, concatenation, comparison, classification, tokenization, numeric conversion, and buffer safety.
- 09PointersMemory addresses, pointer declaration and indirection, null and void pointers, pointer arithmetic, array decay, pointer parameters, qualifiers, function pointers, and pointer safety.
- 10Composite TypesStructures, nested records, structure arrays and pointers, unions, enumerations, type aliases, memory alignment, and padding.
- 11Dynamic MemoryStorage regions, allocation, resizing, release, dynamic arrays and records, ownership, object lifetime, memory faults, and cleanup patterns.
- 12RecursionRecursive functions, base and recursive cases, call stacks, execution tracing, direct and indirect recursion, tail recursion, depth limits, stack overflow, and iterative conversion.
- 13File HandlingFile streams, modes, opening and closing, text and binary files, formatted and block I/O, positioning, end-of-file detection, and error handling.
- 14Program ModularitySource and header files, declarations, external and internal linkage, storage-class specifiers, include guards, macros, conditional compilation, and separate compilation.
- 15DebuggingCompiler warnings, defensive programming, assertions, error codes, debugger workflows, memory diagnostics, sanitizers, unit tests, boundary tests, and regression tests.