Lesson content
Read, practise, then check your understanding
C is a general-purpose, compiled programming language created by Dennis Ritchie at Bell Labs in the early 1970s. It grew alongside Unix: a small language could express operating-system code efficiently while remaining portable across machines. Modern C is standardized by ISO; important editions include C89/C90, C99, C11, C17, and C23. Compilers may support different editions, so production projects should state the standard they require.
Why C still matters
C exposes a compact abstraction over machine memory. It offers structured control flow, functions, arrays, structures, pointers, and a small standard library without automatic garbage collection or a large runtime. That makes it common in operating systems, embedded firmware, device drivers, databases, language runtimes, networking libraries, and performance-critical components.
Its strengths—predictable layout, direct memory access, portability, and mature tooling—also create responsibility. The programmer must respect object lifetimes, array bounds, types, and resource ownership. C is not “unsafe by default” so much as explicit by default.
From source to executable
A typical build passes through four conceptual stages:
- The preprocessor expands directives such as
#includeand macros. - The compiler parses and translates C into assembly or object code.
- The assembler creates machine-code object files.
- The linker combines objects and libraries, resolving external names.
With GCC or Clang, one command usually drives all stages:
cc -std=c17 -Wall -Wextra -Wpedantic hello.c -o hello
./hello
On Windows, use a supported toolchain such as Visual Studio’s MSVC, LLVM/Clang, or GCC through MSYS2. An editor is not a compiler; configure both the editor and toolchain, then verify cc --version or the equivalent command.
Your first program
#include <stdio.h>
int main(void) {
puts("Hello, C!");
return 0;
}
stdio.h declares the standard input/output functions. main is the hosted program entry point. puts writes a line, and returning 0 reports success to the environment.
Build for feedback
Warnings are part of the development workflow, not cosmetic noise. A practical debug build is:
cc -std=c17 -Wall -Wextra -Wpedantic -Wconversion -g main.c -o app
During testing, Clang and GCC sanitizers can expose invalid memory use and undefined behavior:
cc -std=c17 -g -fsanitize=address,undefined main.c -o app
Compile often, read the first diagnostic first, and keep programs small while learning. Every later chapter builds on this toolchain.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.