- Restate the problem in your own words.
- Identify inputs, outputs and constraints.
- Work through a small example manually.
- Write pseudocode or a flowchart.
- Implement the smallest working solution.
- Compile with warnings.
- Test normal, boundary and invalid inputs.
- Refactor names and remove duplicated logic.
Use:
gcc -std=c11 -Wall -Wextra -Wpedantic program.c -o programWarnings often reveal mistakes even when compilation succeeds. Read the first diagnostic carefully; later errors may be consequences of an earlier one.
For loops, write down the loop counter, condition, important variables and output for each pass.
| Iteration | i |
sum before |
sum after |
|---|---|---|---|
| 1 | 1 | 0 | 1 |
| 2 | 2 | 1 | 3 |
| 3 | 3 | 3 | 6 |
This trace corresponds to summing 1 through 3.
- Typical input.
- Minimum and maximum allowed values.
- Zero and negative values where relevant.
- Empty string or one-character string.
- Invalid input.
- Cases that could cause overflow or out-of-bounds access.
C does not promise a particular result for undefined behavior. Examples include out-of-bounds array access, dereferencing invalid pointers, using uninitialized automatic variables, and signed integer overflow. Do not explain such examples by claiming a specific output.
- Use meaningful names.
- Keep functions focused.
- Initialize variables before use.
- Check input and file operations.
- Use braces consistently.
- Avoid magic numbers; name important constants.
- Comment why a decision is made, not every obvious line.
Take one old program from the repository, add input validation, compile with warnings and document three test cases.