BCA Sem 1 | Unit 1 | Computer Concepts & C Programming
Dry-run and its Use in C Programming — BKNMU Junagadh
Manual Debugging, Tracing Code Execution, Variable Value Tracking & Problem Solving
To successfully dry-run an algorithm or C program, you must perform three main manual tracking tasks:
1. Execution Flow
Manually follow the sequence of instructions, noting how logic jumps with Decisions (IF) and branches.
2. Memory Tracking
Record every change in variable values after *every* processing statement executes, simulating CPU registers.
3. Bug Detection
Compare the **actual output** generated manually with the **expected output** defined in the algorithm.
The Process of Tracing Variable States:
You move sequentially through the algorithm, constantly updating a mental or paper "memory box" of variable values.
Let's dry-run a simple algorithm to find the sum of two numbers to track variable states:
Problem: Calculate Sum of A and B.
Here is how a programmer tracks the states during a dry-run of the above algorithm, using test values (e.g., A=10, B=5):
| Step No. | Operation / Statement | Memory: Variable A | Memory: Variable B | Memory: Variable Sum | Output Console |
|---|---|---|---|---|---|
1 | START Logic | ? (Garbage) | ? (Garbage) | ? (Garbage) | (None) |
2 | INPUT A, B (Test Values: 10, 5) | 10 | 5 | ? (Garbage) | (None) |
3 | Processing: Sum = A + B | 10 | 5 | 15 | (None) |
4 | PRINT Sum | 10 | 5 | 15 | Output: 15 |
5 | END Logic | 10 | 5 | 15 | (None) |
Manual Tracing Required
Must be performed by the programmer using paper and pen; computers cannot perform a dry-run.
Logical Accuracy Verification
Every single step is followed strictly according to logical rules, not compiler specific syntax rules.
Definiteness (Unambiguous)
The trace must never run endlessly; it must conclude at a defined logical terminal step.
Effective Effectiveness
The process must identify precise logical flaws by comparing actual results with anticipated outcomes.
- Definition: Manual step-by-step trace of program logic without a computer.
- Main Goal: To detect and correct Logical Errors (bugs) in an algorithm.
- Decision Flow: Following execution sequence, especially branching conditions.
- Memory State: Tracking exact changes to variable values after every instruction.
- Termination Rule: Ensuring the logic has a clear path to the END terminal, avoiding infinite loops.
- Garbage Value: Residual memory data present in uninitialized variables.
- Verification Tool: Essential for verifying algorithm characteristics like definiteness and finiteness.