IT 232

C Programming

TU BIM · Semester 1 · BIM curriculum effective from 2021

Requirement
required
Credits
3
Study Guide
12 units available

Chapter notes

Authoritative study guide across 12 syllabus units

Open a unit to read its study notes.

Unit 1: Introduction to C Programming· 3 LHs· ~4 marks

Pass path: Learn the ANSI flowchart symbols and the structure of a C program in Part 1 and Part 2. Top path: Study compilation pipeline mechanics, linker vs loader responsibilities, and debugging strategies in Part 3 and Part 4.

Part 1: Core Concepts (2 Marks)

  • ★ Algorithm: A finite, unambiguous, step-by-step sequence of computational instructions that takes zero or more inputs and terminates within finite time, producing at least one defined output.
  • ★ Structured Programming: A programming paradigm emphasizing modular code organized into functional blocks using single-entry/single-exit control structures (sequence, selection, iteration), strictly avoiding unstructured jumps (goto).
  • ★ Flowchart: A standardized graphical representation of an algorithm displaying the sequential flow of execution through ANSI symbols connected by directional flowlines.

Part 2: Structural Frameworks (10 Marks)

1. ANSI Standard Flowchart Symbols

Flowchart Blueprint Symbols

Flowchart Symbols
Flowchart Symbols

When asked to present the standard blueprint symbols utilized in algorithmic flowcharts:

  1. Terminal (Oval / Rounded Rectangle): Denotes the unequivocal start or termination point of the program logic (Start, Stop, End).
  2. Input / Output (Parallelogram): Represents any data acquisition operation from the user (Input N, Read A, B) or result presentation on the screen (Print Sum, Display Average).
  3. Process (Rectangle): Indicates arithmetic computations, data assignments, or variable initialization (Sum = A + B, i = 1, Tax = Gross * 0.15).
  4. Decision / Branching (Diamond): Represents a conditional logical evaluation that produces exactly two outgoing path options based on boolean criteria (Is A > B? →\rightarrow True / False).
  5. Connector (Circle): Connects intersecting or complex flowlines on the same page, preserving visual clarity without messy line overlaps.

2. The Complete Compilation Pipeline in C

When explaining how a C program transforms from source code to execution:

  1. Source Code (.c): Human-readable high-level C code written in an editor.
  2. Preprocessor: Processes directives beginning with # (#include, #define), expanding macro constants and copying header file declarations into expanded source code (.i).
  3. Compiler: Translates preprocessed source code into platform-specific assembly language instructions (.s), performing syntax and lexical analysis.
  4. Assembler: Converts assembly instructions into machine-level binary object files (.obj / .o), leaving library references unresolved.
  5. Linker: Combines the object file with compiled C runtime library functions (e.g., printf implementation in libc) to generate a standalone executable file (.exe).
  6. Loader: Operating system module that copies the executable from secondary storage into main RAM, allocates memory segments (code, data, stack, heap), and transfers CPU control to main().

Part 3: Distinction Tables

Programming Approaches: Top-Down vs. Bottom-Up Design

Dimension Top-Down Programming (e.g., Structured C) Bottom-Up Programming (e.g., OOP in Java/C++)
Architectural Focus Breaks the main problem downward into smaller subroutines Builds low-level modules first, combining them into systems
Primary Decomposition Functions, procedures, and modules Classes, encapsulated objects, and interfaces
Data Flow & Security Global data moves freely between functions; low security Data is encapsulated within objects; private data hiding
Code Reusability Limited; tightly coupled to specific function logic High reusability achieved through inheritance and polymorphism

Part 4: Worked Problems & Exam Traps

Types of Programming Errors in C

  1. Syntax Errors: Violations of C grammar rules detected by the compiler before execution (e.g., missing semicolon ;, undeclared identifier).
  2. Runtime Errors: Errors causing abrupt program crashes during execution (e.g., division by zero x / 0, segmentation fault from dereferencing a null pointer).
  3. Logical Errors: The program compiles and executes without crashing, but yields mathematically incorrect results due to flawed algorithm design (e.g., writing while(i > 10) instead of while(i < 10)).

Students lose marks here because they draw generic non-standard shapes for flowchart decisions, and confuse the Linker (combines object files with libraries) with the Loader (loads executables into RAM).