Skip to content
Preptima
easyConceptCodingEntry

In an online assessment, "what does this code print?" questions keep catching you out. How do you answer them quickly without guessing?

Use code tracing, not reading. Write a small table with one column per variable and one row per step, count loop iterations from the bounds first, and apply the language's own rules for integer division, references and evaluation order. Skim the options to see which rule the question is testing.

4 min readUpdated 2026-10-10

Answer

Short answer

Trace the code; do not read it. Code tracing means writing a table with one column per variable and one row per step, then filling it in mechanically. Most wrong answers to output prediction questions come from four rules: integer division, references versus copies, loop bounds and evaluation order. Skim the answer options first, because they usually reveal which rule is being tested.

Was this answer helpful?

Likely follow-ups

  • A Java method writes arr[0] = 99 and then sets arr to a new array. Which of the two changes does the caller see, and why?
  • How does the result of -7 / 2 change if the same snippet is rewritten in Python with //?
  • Why is i++ + ++i well defined in Java but undefined behaviour in C?

Related questions