Skip to content
LumenaryAcademy

Lumenary CS · Programming languages

C

The small, fast language underneath operating systems, databases and language runtimes, taught as modern C17 with an eye on C23.

C is a small, compiled language created at Bell Labs in the early 1970s to write the Unix operating system, and it still sits underneath much of computing: the Linux kernel, embedded firmware, SQLite and PostgreSQL, the interpreters of Python, Ruby and Lua, Git and curl. It gives you direct control over memory and very little protection from mistakes, which is why it is both fast and famously unforgiving. Its calling conventions and data layouts are also the common language through which almost every other language talks to the operating system and to each other.

This course teaches modern C: the C17 standard, with notes on what C23 adds and which compilers support it. It goes from compiling a first program, through types, pointers, strings, structs and dynamic memory, to the preprocessor, the standard library, undefined behaviour, sanitizers, testing and build tools, and ends with a hash-table project. It assumes the Start level of Lumenary CS or equivalent experience: you know what a variable, a loop and a function are. No previous C is needed.

To run the programs you need a C compiler. On Linux install GCC or Clang from your distribution (sudo apt install build-essential on Debian and Ubuntu); on macOS run xcode-select --install for Apple's Clang; on Windows use Visual Studio's C/C++ tools, MSYS2's GCC, or a Linux distribution under WSL. C has no official online playground, because it is an ISO standard rather than a single project, but Compiler Explorer can compile and run C in the browser with many versions of GCC and Clang.

AI-draftedAwaiting review by a computer scientist
  • Chloe · The Designer
    “Why is the language built this way?”
  • Margaret · The Profiler
    “What does it print, and what does it cost?”
  • Gideon · The Language Lawyer
    “What exactly does the language guarantee?”

Foundations · 4 lessons

The core language

Compiling and running C, its types and operators, control flow and functions, and the pointers and arrays that everything else is built on.

  1. 1First steps in CWhere C came from, why it is still everywhere, and how a source file becomes a running program. 50 min
  2. 2Types, values and operatorsWhat C's integer and floating-point types really hold, how C converts between them, and the operators that work on them. 55 min
  3. 3Control flow and functionsDecisions, loops and switch statements in C, and functions with prototypes, pass-by-value, recursion, scope and static storage. 55 min
  4. 4Pointers and arraysAddresses, dereferencing, pointer arithmetic, how arrays decay to pointers, and function pointers with qsort. 60 min

Practice · 3 lessons

Text, data and memory

Strings as arrays of bytes, structs, enums and unions for modelling data, and dynamic memory with the bugs it invites and the sanitizers that catch them.

  1. 5Strings and textStrings as arrays of bytes ending in zero, the string.h toolkit and its traps, safe formatting and parsing, and UTF-8. 60 min
  2. 6Structs, enums and unionsGrouping data into records, naming choices with enumerations, sharing storage with tagged unions, and what padding does to memory layout. 55 min
  3. 7Dynamic memory and its bugsThe stack, static storage and the heap, malloc, calloc, realloc and free, ownership, and the sanitizers that catch the mistakes. 65 min

Professional · 3 lessons

C as professionals write it

Headers, the preprocessor and the standard library, undefined behaviour and how to test against it, and make and CMake builds for a complete hash-table project.

  1. 8Headers, the preprocessor and the standard libraryHow C programs are split into files, what the preprocessor really does, and a working tour of the standard library. 65 min
  2. 9Undefined behaviour, sanitizers and testingWhat the C standard leaves undefined, how optimising compilers exploit it, and the checks, tools and tests that keep real C code correct. 70 min
  3. 10Build tools and a project: a word-frequency counterA hash table in idiomatic C, tested against a reference, split into a library and built with make and CMake, with notes on the tools professionals use and where to go next. 75 min

Further reading and resources