CSS Computer Science (Optional) — Paper-I, Section-A, Topic II subtopic. Appeared as a past paper question (2016). Complements Program Development and Execution page.
The Full Pipeline: Source Code → Executable
- Source code (.c / .cpp) — human-written code
- Preprocessing — preprocessor directives resolved (
#include, #define, macro expansion) → produces expanded source
- Compilation — compiler translates preprocessed source into assembly code
- Assembly — assembler converts assembly code into object code (machine code,
.obj/.o), but not yet linked
- Linking — linker combines object code with required libraries (standard library, other object files) and resolves external references → produces the final executable (.exe)
- Loading — at run time, the OS loader loads the executable into memory and transfers control to start execution
Diagram (textual)
Source (.c) → Preprocessor → Expanded Source → Compiler → Assembly (.s) → Assembler → Object Code (.o) → Linker (+ libraries) → Executable (.exe) → Loader → Running Program
Key Distinctions
- Object code is machine code for just one file — may reference functions from other files/libraries it doesn't yet have addresses for
- Linker resolves those references, producing one complete, runnable executable
- Static linking embeds library code directly into the executable; dynamic linking links to shared libraries (.dll/.so) at load/run time
Worked Example
Given a tiny C program:
#include <stdio.h>
#define PI 3.14
int main() {
printf("%f", PI);
return 0;
}
- Preprocessing:
#include <stdio.h> is replaced with the contents of the stdio header; PI is textually replaced with 3.14 everywhere it appears
- Compilation: the expanded source is translated into assembly instructions for
printf("%f", 3.14); return 0;
- Assembly: the assembler turns those assembly instructions into object code (
hello.o) — machine code, but printf is only referenced, not yet resolved