Tips when tracing codes in an exam?

hey guys, im having a pretty hard time tracing codes in exams/quizzes and i was wondering if you guys could give me tips on how to trace and can anyone give me a site so i could practice my tracing?
I do not know of a site, but this is a critical skill to debugging.

Get a sheet of scratch paper.
use a straight edge to make some columns for each variable in the code.
write down the current value of each variable after each line of code executes.

the last line should contain the answer to the problem for the typical question of this type.

If the code calls a sub-routine, you need to recursively do this with another sheet of paper for each subroutine. If the code is recursive, you need one sheet for each recursive call, and put the call # on the sheet in the corner.

*** Sheet is logical, you can use 1 sheet for several routines if they are tiny.

This can get really hairy with arrays or structs or classes or wore, arrays/vectors/etc of classes that contain classes. At some point it becomes too much for a human, and you have to try other techniques like inserting print statements into your code to capture the values, or tracing in the debugger. Only a very sadistic professor would do this to you on an exam though ...
Last edited on
Topic archived. No new replies allowed.