Sign up to track your progress

Create an account to save your progress, complete exercises, and earn achievements.

ANSI C (C89)

The classic ANSI C university syllabus, taught in its traditional order from tokens and operators through arrays, strings, functions, structures, pointers, files, and linked lists. Every program you write is compiled as strict C89 with pedantic errors, exactly the dialect old exam papers assume, but written correctly: real prototypes, checked return values, safe input, and AddressSanitizer verifying every run. Includes exam notes wherever old compilers and question papers differ from what the language actually guarantees.

Beta

This course is in beta. You get early access while we're still writing and refining it, so lessons may change, and new content is added regularly. Spotted a problem? Feedback is welcome.

68 lessons 34 hours

Support Free C++ Education

Help us keep this platform free for everyone! Your support enables us to create more high-quality lessons, exercises, and interactive content.

Become a Patron

Course Curriculum

Getting Started with C (4 lessons)

How a C program goes from source file to running executable, the anatomy of main, and your first complete programs compiled and run with gcc.

1
How a Computer Runs Your Program

What source code, the compiler, the linker, and the executable each are, and the journey a .c file takes before the machine can run it.

20 minutes

2
The Anatomy of a C Program

The sections of a C source file, what main is, printing with printf, and compiling and running your first program with gcc.

25 minutes

3
Variables, Input, and a First Real Program

Declare variables, read values with scanf, and put both together in a complete interest calculation program of the kind every C exam opens with.

30 minutes

4
Chapter 1 Summary and Quiz

Recap of the compile-and-run pipeline, program anatomy, and first programs.

15 minutes

Constants, Variables, and Data Types (6 lessons)

The tokens C programs are built from, the basic types and their sizes, constants in all their literal forms, enumerations for naming a set of them, and a first look at storage classes.

1
Tokens, Keywords, and Identifiers

The C character set, the token kinds the compiler sees, reserved keywords, and the rules for naming identifiers.

20 minutes

2
Data Types and Their Sizes

int, char, float, double, signed and unsigned variants, sizeof, and why exam papers built on 16-bit compilers quote different sizes than your machine prints.

30 minutes

3
Constants and Symbolic Names

Integer, floating, character, and string literals, const-qualified variables, and #define symbolic constants and when to use each.

25 minutes

4
Enumerations

enum for naming a set of related integer constants: numbering from zero, explicit values, why an enum constant is just an int, and the compile-time constant C otherwise lacks.

25 minutes

5
Storage Classes: A First Look

What auto, static, extern, and register mean on a declaration, previewed here because exam papers ask early; the full story arrives with functions.

20 minutes

6
Chapter 2 Summary and Quiz

Recap of tokens, types, sizes, constants, and storage class keywords.

15 minutes

Operators and Expressions (6 lessons)

Every operator family in C, how expressions are evaluated and converted, and the precedence and associativity rules exam questions love to probe.

1
Arithmetic, Relational, and Logical Operators

The core operator families, integer versus floating division, the modulo operator, and how relational results are just ints.

25 minutes

2
Assignment, Increment, and Conditional Operators

Compound assignment, prefix and postfix ++ and --, the ternary operator, and why classic exam expressions like i++ + ++i have no defined answer.

30 minutes

3
Bitwise and Special Operators

Shifts, AND, OR, XOR, complement, plus the comma operator and sizeof as an operator.

25 minutes

4
Precedence, Associativity, and Type Conversions

How C decides evaluation order on paper, implicit arithmetic conversions, and explicit casts.

30 minutes

5
The Math Library and Numerical Hazards

math.h and the -lm link step, floating point round-off and why == fails on doubles, and the arithmetic C leaves undefined: division by zero and signed overflow.

25 minutes

6
Chapter 3 Summary and Quiz

Recap of the operator families, conversions, and precedence rules.

15 minutes

Input and Output (4 lessons)

The standard I/O toolkit: character I/O with ctype.h, the full printf format language, and scanf used with its widths, its scansets, and its return value checked like it always should be.

1
Character I/O with getchar and putchar

Reading and writing one character at a time, EOF, classifying and converting characters with ctype.h, and a first taste of loops over input.

30 minutes

2
Formatted Output with printf

Conversion specifiers, field width, precision, and every flag, with the exact-output discipline exams and this platform both demand.

35 minutes

3
Formatted Input with scanf

Conversion specifiers on input, why arguments need &, the whitespace rules, field widths and skipped fields, scansets, and treating the return value as the conversion count it is.

45 minutes

4
Chapter 4 Summary and Quiz

Recap of character and formatted I/O.

15 minutes

Branching (4 lessons)

Choosing between paths: if in all its forms, switch, the conditional operator as a branch, and goto covered honestly because the syllabus includes it.

1
if and the else-if Ladder

Simple if, if-else, nesting, the else-if ladder, and the dangling-else rule that decides which else binds where.

30 minutes

2
switch Statements

The switch statement, case labels, fallthrough as both a bug and a tool, and default.

25 minutes

3
goto and Structured Alternatives

What goto does, the one cleanup pattern where C programmers still accept it, and the structured forms that replace it everywhere else.

20 minutes

4
Chapter 5 Summary and Quiz

Recap of branching constructs.

15 minutes

Loops (4 lessons)

Repetition with while, do-while, and for, controlling loops with break and continue, and the nested-loop patterns behind every exam pattern-printing question.

1
while and do-while

Entry-controlled versus exit-controlled loops, sentinel-driven input loops, and choosing between the two forms.

25 minutes

2
The for Loop

The three-part header, counting up and down, and the idioms that make for the default counting loop.

25 minutes

3
break, continue, and Nested Loops

Leaving early, skipping an iteration, and the nested loops behind matrix traversal and the pattern-printing questions on every paper.

30 minutes

4
Chapter 6 Summary and Quiz

Recap of loop forms and loop control.

15 minutes

Arrays (4 lessons)

Contiguous storage in one, two, and more dimensions, initialization rules, why C never checks your index, and the classic searching and sorting algorithms.

1
One-Dimensional Arrays

Declaring, initializing, and traversing arrays, counting with a computed index, and why an out-of-bounds index is undefined behaviour rather than an error message.

35 minutes

2
Two-Dimensional Arrays

Matrices in row-major storage, nested-loop traversal, the matrix addition and multiplication programs exams expect, and how the rules generalize to three dimensions and beyond.

45 minutes

3
Classic Array Algorithms

Linear search, binary search, and bubble sort, written cleanly and traced by hand the way an examiner asks.

30 minutes

4
Chapter 7 Summary and Quiz

Recap of arrays and the classic algorithms.

15 minutes

Character Arrays and Strings (5 lessons)

Strings as char arrays with a null terminator, reading them safely, the string library functions plus hand-written versions of each, and tables of strings for lists of names.

1
Strings and the Null Terminator

What a C string actually is in memory, string literals, and the difference between length and size.

25 minutes

2
Reading and Printing Strings

printf with %s, scanf's %s and its buffer-overrun trap, fgets as the safe reader, and why gets no longer exists in the language.

30 minutes

3
The String Library

strlen, strcpy, strcat, and strcmp, then writing each one yourself, the exam question that never goes away.

30 minutes

4
Tables of Strings

Two-dimensional char arrays as lists of names, why one subscript names a whole string, and sorting a name list with strcmp and strcpy.

30 minutes

5
Chapter 8 Summary and Quiz

Recap of strings and the string library.

15 minutes

Functions (5 lessons)

User-defined functions, prototypes, pass-by-value, recursion, and the full story on scope, lifetime, and storage classes.

1
Defining and Calling Functions

Function definitions, prototypes and why they matter, return types, and void functions and parameters.

30 minutes

2
Pass by Value

Every argument is a copy: what that means, what it forbids, and the swap function that fails because of it.

25 minutes

3
Recursion

Base case and recursive case, factorial, Fibonacci, and tracing the calls the way an exam answer requires.

30 minutes

4
Scope, Lifetime, and Storage Classes

Block scope and file scope, static locals that survive between calls, extern across files, and register as history.

30 minutes

5
Chapter 9 Summary and Quiz

Recap of functions, recursion, and storage classes.

15 minutes

Structures and Unions (5 lessons)

Grouping related data with struct, arrays of records, passing structures to functions, and unions and bit-fields.

1
Defining Structures

Struct declarations, members, initialization, the dot operator, and typedef for cleaner names.

25 minutes

2
Arrays of Structures

Record-keeping programs: an array of student records, sorted and searched, the staple of every structures question.

30 minutes

3
Structures and Functions

Passing structures by value, returning them, and when copying a struct starts to cost.

25 minutes

4
Unions and Bit-Fields

How a union overlays its members, what reading the wrong member means, and bit-fields for packed flags.

25 minutes

5
Chapter 10 Summary and Quiz

Recap of structures, unions, and bit-fields.

15 minutes

Pointers (5 lessons)

Addresses as values: declaring pointers, pointer arithmetic over arrays, passing addresses to functions, and pointers with strings and structures.

1
Pointer Basics

Declaring a pointer, the address-of and dereference operators, NULL, and drawing the memory picture that makes pointers ordinary.

30 minutes

2
Pointers and Arrays

Pointer arithmetic, why a[i] is *(a+i), array decay in function calls, and the limits the standard puts on arithmetic.

30 minutes

3
Pointers and Functions

Passing addresses so a function can modify the caller's variables: swap done right, and out-parameters as C's second return value.

30 minutes

4
Pointers with Strings and Structures

char pointers versus char arrays, walking a string by pointer, pointers to structures, and the arrow operator.

30 minutes

5
Chapter 11 Summary and Quiz

Recap of pointers across arrays, functions, strings, and structures.

15 minutes

File Handling (5 lessons)

Persistent data with the FILE API: opening and closing with every error checked, text and binary I/O, random access, and command-line arguments.

1
Opening and Closing Files

fopen and its modes, why the NULL check is not optional, fclose, and what a FILE pointer represents.

25 minutes

2
Reading and Writing Text Files

fgetc, fputc, fgets, fprintf, and fscanf, with end-of-file handled correctly.

30 minutes

3
Binary Files and Random Access

fread and fwrite on records, fseek and ftell, and when binary beats text.

30 minutes

4
Command-Line Arguments

argc and argv: where they come from, converting argument strings to numbers, and validating what the user typed.

20 minutes

5
Chapter 12 Summary and Quiz

Recap of file handling and command-line arguments.

15 minutes

Dynamic Memory and Linked Lists (4 lessons)

Requesting memory at run time with malloc, calloc, realloc, and free, then spending it on the linked list every syllabus culminates in.

1
malloc, calloc, realloc, and free

The allocation functions, checking every return, ownership as a discipline, and what a leak looks like under AddressSanitizer.

30 minutes

2
Building a Linked List

Self-referential structures, allocating nodes, linking them, and printing the list.

30 minutes

3
Insertion and Deletion

Inserting at the head, the tail, and mid-list, deleting a node without leaking it, and freeing the whole list.

30 minutes

4
Chapter 13 Summary and Quiz

Recap of dynamic allocation and linked lists.

15 minutes

The Preprocessor (3 lessons)

The text-substitution pass before compilation: macros and their traps, file inclusion, and conditional compilation.

1
Macros and File Inclusion

#define for object-like and function-like macros, the parenthesization traps, #include, and macros versus functions.

30 minutes

2
Conditional Compilation

#ifdef, #ifndef, #if, include guards, and using them to compile different code for different situations.

25 minutes

3
Chapter 14 Summary and Quiz

Recap of the preprocessor.

15 minutes

Writing Real Programs (4 lessons)

Bringing the course together: structuring a larger program, the honest map between exam C and modern C, and a complete record-management capstone.

1
Structuring a Larger Program

Top-down design, splitting work into functions, naming, and the habits that keep a 300-line program readable.

25 minutes

2
Exam C versus Modern C

void main, conio.h, gets, 2-byte int, and undefined-behaviour output questions: what old exam papers expect, what is actually correct, and how to answer both ways with your eyes open.

30 minutes

3
Capstone: A Records Manager

A complete menu-driven student records program using structs, dynamic memory, files, and every check the course taught.

45 minutes

4
Chapter 15 Summary and Quiz

Recap of the whole course, plus the craft that has no lesson of its own: the four kinds of error, testing against designed data, the three ways to locate a bug, a checklist of C's classic traps, and when program efficiency is worth caring about.

30 minutes