AP Computer Science A Practice Quiz: Array Traversals
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Test your understanding with short quizzes. This quiz has 10 questions to check your progress.
Question 1 of 10
All Questions (10)
A) Array Initialization
B) Array Traversal
C) Array Declaration
D) Array Assignment
Correct Answer: B
The text defines traversing an array as 'when repetition statements are used to access all or an ordered sequence of elements in an array.'
A) The index of the current element
B) A reference to the current element
C) The memory address of the array
D) A copy of the current element's value
Correct Answer: D
The text states, 'For each iteration, the enhanced for loop variable is assigned a copy of an element without using its index.'
A) 5
B) 10
C) 20
D) 30
Correct Answer: C
The text explains that 'Assigning a new value to the enhanced for loop variable does not change the value stored in the array.' The variable 'value' is a copy, so modifying it does not affect the original 'data' array. Therefore, data[1] remains 20.
A) It requires manual management of an index variable.
B) It is the most efficient way to modify all elements in an array.
C) It accesses elements without using their indices.
D) It can only be used to traverse an array backwards.
Correct Answer: C
The text explicitly mentions that in an enhanced for loop, 'the enhanced for loop variable is assigned a copy of an element without using its index.'
A) 6
B) 12
C) 14
D) 20
Correct Answer: C
The code traverses the 'nums' array. The loop variable 'n' takes on the values 2, 4, 6, and 8. The 'if' condition (n > 5) is true for 6 and 8. The sum is calculated as 6 + 8, which equals 14. This demonstrates determining the result of a traversal.
A) Because the loop variable is only a copy of the element's value.
B) Because arrays are always read-only during traversals.
C) Because the operation requires an explicit index, which is not available.
D) Because the compiler optimizes away the assignment statement.
Correct Answer: A
The provided text directly supports this by stating that the loop variable is assigned a 'copy of an element' and that assigning a new value to this variable 'does not change the value stored in the array.' The reason for this behavior is that the modification is happening to the copy, not the original element.
A) Conditional statements (if-else)
B) Repetition statements (loops)
C) Object instantiation (new)
D) Method declarations
Correct Answer: B
The text states, 'Traversing an array is when repetition statements are used to access all or an ordered sequence of elements in an array.'
A) Yes, because the loop iterates through every element.
B) Yes, but only if the array was empty to begin with.
C) No, because assigning to 'g' only changes a temporary copy.
D) No, because an enhanced for loop cannot be used with primitive types like int.
Correct Answer: C
The provided content explicitly states that 'Assigning a new value to the enhanced for loop variable does not change the value stored in the array.' The variable 'g' is a copy, so setting it to 0 has no effect on the original 'grades' array.
A) The enhanced for loop is slower than a traditional for loop.
B) The enhanced for loop cannot be used to modify the contents of the array.
C) The enhanced for loop can only access every other element.
D) The enhanced for loop requires more memory than a traditional for loop.
Correct Answer: B
Because the loop variable is a copy, any changes made to it are not reflected in the original array. Therefore, this type of loop cannot be used to directly modify the array's elements via assignment to the loop variable.
A) XXX
B) ABC
C) AAA
D) CCC
Correct Answer: C
The traversal iterates three times. The line 's = "X"' modifies a copy and does NOT change the 'words' array. Inside the loop, 'result += words[0]' is executed three times. Since the 'words' array is never changed, 'words[0]' is always "A". Therefore, "A" is appended to 'result' three times, producing "AAA".