---
title: "Compilation, linking and loading process"
subject: "Computer Programming"
chapter: 1
key: "semester_1/computer_programming:compile-link-load-process"
source: https://www.bctengineer.com/q/semester_1/computer_programming/compile-link-load-process
site: BCT Engineering
---

# Compilation, linking and loading process

Computer Programming · Chapter 1: Overview of computer software & programming languages

- Asked in: 2073 Shrawan, 4 marks
- Video: [C_06 Execution Process of a C Program | C Programming Tutorials](https://www.youtube.com/watch?v=_FOkG5D4NBo) — Jenny's Lectures CS IT
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/compile-link-load-process
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-1

## Question

Explain the program compilation, linking and loading process with example.

## Short answer

A C program goes through preprocessing, compilation (source to object code), linking (object code combined with libraries into an executable), and loading (copying the executable into RAM to run). For example, hello.c becomes hello.o, then hello.exe, and loading displays Hello.

## Answer

After it is written (edited), a C program goes through four stages before it runs: preprocessing, compiling, linking and loading.

```text
 Source  --> Preprocessor --> Compiler --> Object
 (prog.c)    (#include,                    (prog.o)
              #define)                        |
                                             v
 Running <-- Loader <-- Executable <-- Linker <-- Libraries
 process     (RAM)      (prog.exe)               (stdio, math)
```

1. **Preprocessing:** directives such as `#include <stdio.h>` and `#define` are processed.
2. **Compilation:** the compiler checks syntax and converts the source into machine-level object code. Syntax errors are reported here.
3. **Linking:** the linker joins the object code with library code (for example, the code of `printf`) and creates the executable file.
4. **Loading:** the loader copies the executable from disk into main memory and starts execution at `main()`.

Example: for `hello.c` containing `printf("Hello");`, compiling gives `hello.o`, linking with the C library gives `hello.exe`, and running it loads the file into RAM and displays *Hello*.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is the correct order?
   A. Preprocessing, compilation, linking, loading
   B. Loading, linking, compilation, preprocessing
   C. Compilation, preprocessing, loading, linking
   D. Linking, preprocessing, compilation, loading
   Answer: A. Directives are processed first, then compile, link and finally load. (Key point: Order of stages)

2. Syntax errors are reported during
   A. loading
   B. compilation
   C. execution only
   D. linking
   Answer: B. The compiler checks syntax and reports syntax errors. (Key point: Compiler stage)

3. During linking, printf code is
   A. written by the compiler from nothing
   B. removed from the program
   C. joined from the C library to create the executable
   D. executed by the preprocessor
   Answer: C. The linker adds library code such as printf. (Key point: Linking stage)

4. The loader
   A. converts source to object code
   B. processes #include directives
   C. joins libraries to object files
   D. copies the executable from disk into main memory and starts execution at main()
   Answer: D. Loading places the executable in RAM and begins at main(). (Key point: Loading)

## Related in Computer Programming

- [Copy string converting lower to upper using pointer](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apointer-array-elements-copy-string-upper) — Computer Programming, chapter 9, asked 3×

## Related in other subjects

- [COM vs EXE; assembling, linking, executing](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Acom-exe-assembling-linking) — Microprocessor, chapter 3
