ZetCode

K&R C tutorials

K&R C is the C programming language as described in the first edition of The C Programming Language by Brian Kernighan and Dennis Ritchie, published in 1978. It is the C of early UNIX, a decade before the ANSI standard: functions have old-style parameter declarations and no prototypes, a missing type means int, and there is no void, const, or enum. Modern C is covered in the C tutorials.

E-books

K&R C is a small language that trusts the programmer: arguments are not checked against parameters, conversions happen silently, and much behaviour is left to the machine. The tutorials teach that dialect and rewrite the classic programs of the book.

The examples are compiled with GCC 13.2 in its oldest language mode, gcc -std=c89 -pedantic -Wall -Wextra. The second compiler is Dennis Ritchie's cc on V7 UNIX (1979), running on a PDP-11 simulated by SIMH; where the 16-bit PDP-11 behaves differently, a section adds a second output block from the simulator. Every example is run before its output is shown.

Getting started

Old-style function definitions, types, operators, control flow, and storage classes.

Characters, arrays and pointers

Character I/O, arrays, pointers, strings, and pointers to functions.

Structures and the preprocessor

Structures, unions, bit-fields, multi-file programs, and the preprocessor.

Input, output and the system

Formatted I/O, files, the standard library, system calls, and command-line arguments.

Classic programs

The calculator, sorting, lists, trees, hash tables, text filters, and the allocator from the book.

Modern use

Porting old code to ANSI C and finding bugs with lint, gdb, and adb.

last modified December 5, 2026