Structured Programming in C
Learn structured programming in C as universities teach it: types, loops, arrays, strings, functions, pointers, structures, dynamic memory and files, with every byte of memory on screen.
- Level
- Beginner
- Time
- About 55 hours
- Modules
- 5
- Lessons
- 18
- Exercises
- 57
C is the language most computer science departments teach first, because it shows how a computer really works. Every variable is a piece of memory with an address, and you are in control of all of it. In this course you can step through every program and watch that memory change, so pointers and the heap become pictures rather than mysteries.
You begin with a single printf and work up to pointers, structures, dynamic memory, linked lists and files. Real C will often let a mistake pass silently, so you also learn the bugs it will not catch, and how to find them. Each exercise is checked against hidden tests, and every reference solution in the course also compiles cleanly with a real C compiler.
What you will learn
- Write correct C programs with variables, conditions, loops and functions
- Store and process data with arrays, strings and structures
- Use pointers to work directly with memory
- Manage memory on the heap, and build linked lists
- Read and write files, and find the bugs C will not catch
Skills you will gain
- Reasoning about memory, addresses and types
- Using pointers safely
- Managing dynamic memory
- Reading compiler errors and warnings
- Debugging undefined behaviour
Before you start
- Basic computer skills: using a browser and typing
- School-level arithmetic
- No programming experience is needed, although the Python course is a gentle way to start
Where it is used
- Operating systems and device drivers
- Embedded systems and the Internet of Things
- Compilers, databases and game engines
- University data structures and systems courses
Modules
Module 1: Getting started
The parts of a C program, the types of its values, how arithmetic really behaves, and how to read input and print neat output.
- 1
Your first C program
The parts every C program has: #include, main, printf and return 0.
- 2
Variables and types
int, double and char: each variable is a named box of memory with an address and a size.
- 3
Operators and expressions
Integer division, the remainder %, casts, ++ and +=, and what happens when a number gets too big.
- 4
Input and output: printf and scanf
Format codes, field widths, and reading numbers with scanf and the & operator.
Module 2: Decisions, loops, arrays and strings
How programs choose and repeat, and how many values of one kind are stored side by side, including text.
- 1
Decisions: if, else and switch
Run code only when a condition is true, chain choices with else if, and pick one case with switch.
- 2
Loops: for, while and do-while
Repeat code with a counter, until a condition fails, or at least once; break and continue.
- 3
Arrays
Many values of one type side by side in memory, indexes from 0, and what happens past the end.
- 4
Strings are char arrays
The '\0' at the end, string.h functions, reading words and lines, and buffers that are too small.
Module 3: Functions and pointers
Splitting programs into functions, understanding the call stack, and using addresses to reach memory directly.
- 1
Functions
Parameters, return values, prototypes, and why changing a parameter does not change the caller's variable.
- 2
Recursion and the call stack
Functions that call themselves: base cases, one frame per call, and what happens when there is no base case.
- 3
Pointers Intermediate
Addresses with &, following them with *, NULL, and a swap function that really swaps.
- 4
Pointers and arrays Intermediate
An array name is the address of its first element, pointer arithmetic, and passing arrays to functions.
Module 4: Structures and dynamic memory
Grouping related values, naming constants, asking for memory at run time, and building data structures from nodes.
- 1
Structures Intermediate
Group related values with struct and typedef, arrays of structs, and the -> operator.
- 2
Constants, enums and macros Intermediate
Give values names with const, enum and #define, write safe macros, and understand what the preprocessor does before compiling.
- 3
Dynamic memory: malloc and free Intermediate
Ask for memory at run time on the heap, give it back with free, and avoid leaks and dangling pointers.
- 4
Linked lists Intermediate
Nodes on the heap joined by next pointers: build, walk, insert at the front, and free.
Module 5: Files and reliable programs
Keeping data after a program ends, and recognising the mistakes that C will let you make.
- 1
Reading and writing files Intermediate
Keep data after a program ends: open files with fopen, write with fprintf, read with fscanf and fgets, and handle a file that cannot be opened.
- 2
Bugs C will not catch Intermediate
Undefined behaviour: what real C does silently, and how to spot each bug before it bites.
Projects
- A student records system Build a program that adds, lists, searches and sorts student records, and saves them in a file so that they are still there next time.
- A library with a linked list Build a program that keeps a library's books in a linked list, and lets you add, remove, borrow and return them.
What to learn next
- Data Structures Lists, stacks, queues, trees, heaps, hash tables and graphs, built in C node by node, with every pointer drawn.
- Algorithms Searching, sorting, recursion, greedy choices, dynamic programming and graph algorithms, with the cost of each one counted.
- Object-Oriented Programming in C++ Classes, constructors and destructors, operators, inheritance, virtual functions, templates, the STL and exceptions, with every object on screen.