← Debugging with gdb/lldb & Memory-Checking Tools

Trace the Off-by-One

medium

This program compiles and runs – it just returns the wrong total, consistently missing the last element. This is the exact bug traced in the lesson’s annotated debugger transcript: before changing anything, trace i and total by hand through every iteration for the sample input (n = 4, values = [1, 2, 3, 4]), the same way the transcript watched them converge on the bug.

Once you can see which value never gets added and why the loop stops one iteration early, the fix is a single character.

Your solution

"Run" uses the sample stdin ("4\n1 2 3 4"). "Submit" checks your code against all 3 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution