NBC 103 • Unit 115 min readHigh Exam Frequency

C History, Program Architecture & Compilation Pipeline

Unit 1: Algorithms, Flowcharts & C Program ArchitectureProblem Solving Using C

👨‍🏫 Professor's Mental Model: The Industrial Car Manufacturing Assembly Line

C program ko ek car manufacturing plant samjho. Source Code (.c) raw blueprints hain. Preprocessor (#include) bahar se mangwaye gaye parts (jaise wheels aur engine) ko jodta hai (.i). Compiler blueprints ko technical assembly instructions (.s) me badalta hai. Assembler use robot machine-code (.o) me badalta hai. Aur Linker runtime libraries (fuel aur electronics) jodh kar final road-ready gadi (.exe) taiyar karta hai!

Academic Lecture Notes & Solved Study Pages

Unit 1 • Core Concepts, Step-by-Step Proofs & Notebook Solutions

3 Notebook Pages
NOTEBOOK PAGE 1 OF 3

1. History & The Middle-Level Philosophy of C

C was developed in 1972 by Dennis Ritchie at Bell Telephone Laboratories (AT&T) in Murray Hill, New Jersey. It was derived from Ken Thompson's B language, which itself originated from BCPL (Basic Combined Programming Language).

Why is C termed a 'Middle-Level Language'?

It combines the user-friendliness, modularity, and data abstractions of High-Level languages (like Java/Python).
While retaining the raw low-level capabilities of Assembly: direct RAM memory manipulation via pointers, bit-level operations, and near-zero runtime abstraction overhead.
C was originally developed to rewrite the UNIX Operating System kernel, proving that a robust OS could be written in a portable structured language.
NOTEBOOK PAGE 2 OF 3

2. The 6 Standard Structural Sections of a C Program

Every well-engineered C program follows a standard 6-section template:

1. Documentation Section: Multi-line comments (/* ... */) containing author name, date, program aim, and revision history. 2. Link Section: Preprocessor directives like #include <stdio.h> linking standard library header declarations. 3. Definition Section: Manifest constants defined using #define MAX 100. 4. Global Declaration Section: Global variables, custom struct declarations, and user-defined function prototypes. 5. main() Function Section: The mandatory entry point of program execution containing declaration and execution statements. 6. Subprogram (UDF) Section: Concrete user-defined function definitions called by main().

Formula / Calculation Syntax:
/* Section 1: Documentation */
// Project: Factorial Engine

/* Section 2: Link Section */
#include <stdio.h>

/* Section 3: Definition Section */
#define SUCCESS 0

/* Section 4: Global Declarations */
int global_counter = 0;
void greet(void); // Prototype

/* Section 5: main() Entry Point */
int main(void) {
    greet();
    return SUCCESS;
}

/* Section 6: Subprogram Definitions */
void greet(void) {
    printf("Welcome to C Architecture!\n");
}
NOTEBOOK PAGE 3 OF 3

3. The 4-Stage C Compilation & Execution Pipeline

Converting human-readable C text into executing machine silicon cycles involves 4 distinct translation phases:

1. Preprocessing (`cpp`):

• Expands all `#include` header files by copying their prototypes into the file.
• Replaces all `#define` macros with their text substitutions.
• Strips all comments (`//` and `/* */`) from the source.
• Generates the Expanded Source Code file (`program.i`).

2. Compilation (`ccl`):

• Performs Lexical Analysis, Syntax Parsing, and Semantic Analysis.
• Optimizes code performance and translates C into target CPU Assembly Language (`program.s`).

3. Assembly (`as`):

• Converts assembly mnemonic instructions into raw binary CPU opcodes and relative memory offsets.
• Produces the Relocatable Object File (`program.o` on Linux, `program.obj` on Windows).

4. Linking (`ld`):

• Combines multiple user object files with pre-compiled standard runtime libraries (e.g., `printf` from libc).
• Resolves absolute memory addresses for function calls.
• Generates the standalone Executable Binary (`a.out` or `program.exe`).

5. Loading (OS Loader):

• Allocates primary RAM space, sets up Stack, Heap, Data Segment, and transfers CPU control to `main()`.
The 4 Stages of the C Compilation Toolchain
StageTool NameInput FileOutput FilePrimary Responsibility
1. PreprocessingC Preprocessor (cpp)program.cprogram.iHeader file inclusion, macro expansion, comment stripping
2. CompilationC Compiler (ccl)program.iprogram.sSyntax/semantic check, optimization, assembly generation
3. AssemblyAssembler (as)program.sprogram.o / .objTranslates assembly mnemonics into machine object code
4. LinkingLinker (ld)program.o + libc.aprogram.exe / a.outResolves external symbols, merges libraries, generates executable
5. LoadingOS Loaderprogram.exeRAM ProcessAllocates memory pages in RAM, initializes stack/heap, executes main()

Interactive Tested Code Example

#include <stdio.h>

#define APP_NAME "DevBCA Engine"
#define VERSION 2.0

int main(void) {
    printf("====================================\n");
    printf("Application: %s\n", APP_NAME);
    printf("Build Version: %.1f\n", VERSION);
    printf("Standard C Version: %ld\n", __STDC_VERSION__);
    printf("Source Compiled At: %s on %s\n", __TIME__, __DATE__);
    printf("====================================\n");
    return 0;
}
💡 Note:Demonstrates preprocessor macro expansion (APP_NAME, VERSION) and standard predefined ANSI C macros (__TIME__, __DATE__, __STDC_VERSION__).

🎯 University Exam Scoring Blueprint

  • In university exams, always draw the 4-stage pipeline boxes: .c -> Preprocessor -> .i -> Compiler -> .s -> Assembler -> .obj -> Linker -> .exe.
  • Mention that main() returns an integer (int main(void)), where return 0 signifies clean exit to the Operating System.
  • Linker errors (e.g. 'Undefined reference to...') occur when a function is declared but its binary body cannot be located.

Top Viva Questions on C History, Program Architecture & Compilation Pipeline

2 Questions
1

What is the difference between Linker and Loader?

2

Why is 'void main()' considered obsolete or bad practice in modern ANSI C?