§1 How to trace
§2 Language details that change answers
| Detail | Behaviour |
|---|---|
| Integer division | 17 / 5 is 3 when both operands are integers; 17 % 5 is 2 |
| Post- vs pre-increment | x++ yields the old value; ++x yields the new value |
| Short-circuit && and || | The right side is skipped when the left side decides the result |
| switch without break | Execution falls through into the next case |
| Array indices | Start at 0; an array of length n ends at n − 1 |
§3 Worked examples
Example 1
Trace: s = 0; for i = 1 to 4: if i % 2 == 0 then s = s + i else s = s − 1. Output s.
- i=1 (odd): s = −1.
- i=2 (even): s = 1.
- i=3 (odd): s = 0.
- i=4 (even): s = 4.
Answer 4
! Common traps
- Stopping a loop one iteration early or late — check the condition with the boundary value.
- Assuming C behaves like Java for expressions such as x++ + ++x (undefined in C).
Coverage source: 2023 ICT Proficiency Certification Examination FAQs (file dated 14 Feb 2023) (third-party copy)