Loading lessons...
The Compiler and How C Programs Run
The Compiler and How C Programs Run
Going from a source file to a running program takes a few steps. In C the key tool is called a compiler (like gcc or clang).
The build pipeline
- You write a
.cfile containing source code. - The preprocessor pulls in headers (the
#includelines). - The compiler translates it into machine code.
- The linker merges things into one final executable.
What is a header?
A line like #include <stdio.h> brings in declarations for standard functions such as printf. It is just instructions saying "grab this library".
Build tools
- gcc and clang are the most popular C compilers, used from a terminal.
- An IDE (like Visual Studio, Code::Blocks, or VS Code with extensions) wraps this so "Run" just works.
How do I compile and run?
gcc hello.c -o hello
./hello
gcc hello.c -o hellocompiles the source into an executable calledhello../helloruns the program (on Windows justhello).
The make of libraries
Real programs rarely stand alone. They link in libraries: reusable code somebody already wrote (like the standard library libc) instead of typing everything from scratch.
TL;DR
- Flow: ``
#include`` header, compile, link, run. gcc source.c -o programcompiles a C file.#include <stdio.h>pulls in standard functions likeprintf.- Libraries let you reuse code instead of reinventing it.