Enhanced for Loop for Arrays

AP Computer Science A· difficulty 4/5

The enhanced for loop <code>for (int x : arr) { ... }</code>

  • A

    Iterates in reverse order by default

  • B

    Cannot be used with arrays — only ArrayList

  • C

    Cannot modify the array element through the loop variable x

    check_circle
  • D

    Allows modification by assigning to x

Explanation

<code>x</code> is a copy of arr[i]. Reassigning x has no effect on arr. To modify arr in place, use the indexed for loop.

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

Related questions