C · 1 · Foundations1 / 35 · 3%
Hello, World & the Compilation Pipeline
How your .c file becomes an executable — the four steps every C program takes.
Examples: gcc, clang, .i / .s / .o files
shortcuts: ← prev · → next · M mark
1
Hello, World
Every C program starts at main() and returns an int status code.
Example
hello.c
#include <stdio.h>
int main(void) {
printf("Hello, World!\n");
return 0;
}Output
Hello, World!
2
The 4-Step Pipeline
Compilation is not one step. Each phase produces a real file you can inspect.
Syntax
one command per stage
gcc -E hello.c -o hello.i // preprocess
gcc -S hello.i -o hello.s // compile to asm
gcc -c hello.s -o hello.o // assemble
gcc hello.o -o hello // link.c → .i → .s → .o → executable
3
#include & the Preprocessor
The preprocessor is a text substitution engine. It runs BEFORE the compiler sees your code.
Example
example
#define PI 3.14159
#define SQUARE(x) ((x) * (x))
#include <stdio.h> // pastes the whole header here
int main(void) {
printf("%f\n", SQUARE(PI));
return 0;
}WATCH OUT
Always wrap macro arguments in parentheses — SQUARE(a+1) without them becomes a+1*a+1.
4
Compile & Run
The compiler + linker turn your code into a binary the OS can execute.
Syntax
shell
gcc -Wall -Wextra -O2 hello.c -o hello
./helloAlways compile with -Wall -Wextra. They catch real bugs.