Part 1: Core Concepts (2 Marks)
- Structured Programming: A programming paradigm that enforces clean logical organization using three fundamental control structures: Sequence, Selection (
if-else,switch), and Repetition (for,while,do-while), strictly avoiding unstructured jumps (goto). - Compilation Pipeline in C: The five-stage build sequence: Preprocessing (
cppexpands macros/headers to.i), Compilation (gccgenerates assembly.s), Assembly (asoutputs relocatable object code.o), Linking (ldresolves external libraries into the final executable.exe), and Loading (OS loads binary into RAM). - Algorithm vs. Flowchart: An algorithm is a finite, unambiguous, step-by-step written procedure for solving a computational problem; a flowchart is the standardized graphical representation of that algorithm using geometric symbols.
- Linker Error vs. Runtime Error: A linker error occurs when the linker cannot resolve external function symbols (e.g., missing
main()or unresolved library symbol); a runtime error occurs during execution (e.g., division by zero, segmentation fault).
Part 2: Structural Frameworks (10 Marks)
Complete C Compilation and Execution Pipeline
- Preprocessor (
cpp): Ingests raw source code (program.c), strips comments, expands header directives (#include), and substitutes symbolic macro definitions (#define) to produce the expanded source file (program.i). - Compiler (
gcc): Performs lexical analysis, syntax parsing, semantic verification, and code optimization, translating the high-level C code into assembly language instructions (program.s). - Assembler (
as): Converts mnemonic assembly code into platform-specific machine code, outputting relocatable binary object files (program.oorprogram.obj). - Linker (
ld): Resolves external cross-references, binds functions from standard libraries (such aslibc.aormsvcrt.lib), and merges multiple object files into a single standalone executable binary (program.exe). - Loader (Operating System): Allocates virtual address space, loads code and static data segments into physical RAM, initializes runtime stack and heap spaces, and passes execution control to the entry point
main().
Part 3: Distinction Tables
| Basis of Comparison | Low-Level Language (Assembly) | High-Level Language (C) |
|---|---|---|
| Hardware Dependency | Strictly tied to specific CPU architecture & register set | Platform-independent (portable source code) |
| Execution Speed | Maximally fast; direct 1:1 hardware translation | Marginally slower due to compiler abstraction |
| Programmer Productivity | Extremely tedious; requires manual register allocation | High productivity; expressive arithmetic syntax |
| Memory Abstraction | Direct physical memory addresses and stack manipulation | Abstract variable identifiers and type safety |
Part 4: Worked Problems & Exam Traps
Algorithm and Compilable C Boilerplate
#include <stdio.h>
int main(void) {
// 1. Sequence: Variable Declaration
int n, sum = 0;
printf("Enter a positive integer: ");
if (scanf("%d", &n) != 1 || n <= 0) {
printf("Error: Invalid positive integer input.\n");
return 1;
}
// 2. Iteration: Loop Accumulation
for (int i = 1; i <= n; i++) {
sum += i;
}
// 3. Selection & Output
printf("Sum of first %d natural numbers = %d\n", n, sum);
return 0;
}
TU Exam Trap: Never confuse
#include <stdio.h>with a pre-compiled library. The.hheader contains only function prototypes and macro definitions; the actual compiled implementation is linked during the linking phase fromlibc.