Informal Code Analysis (Loop Tracing)

AP Computer Science A· difficulty 4/5

What is the final value of x?

<code>int x = 1; for (int i = 1; i <= 3; i++) x *= 2; </code></pre>

  • A

    4

  • B

    8

    check_circle
  • C

    2

  • D

    16

Explanation

x doubles 3 times: 1 → 2 → 4 → 8.

Want 10 more like this — adaptive to your weak spots?

Related questions