Enhanced for Loop for Arrays

AP Computer Science A· difficulty 4/5

Inside <code>for (int x : arr) x = 0;</code>

  • A

    Sets all array elements to 0

  • B

    Throws exception

  • C

    Compile error

  • D

    Sets local copy x to 0; array unchanged

    check_circle

Explanation

<code>x</code> is a local copy of each element (for primitives); modification doesn't affect array.

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

Related questions