AP CSA Unit 4 Day 21: Array Copy Pitfall
Share
Unit 4, Data Collections • Cycle 2
Day 21 Advanced Practice • Harder Difficulty
Focus: Array Copy Pitfall
Hard
Array Copy Pitfall
Advanced Practice Question
Format: Array Copy Pitfall
What is the output?
What is the output?
int[] a = {1, 2, 3};
int[] b = a;
b[0] = 99;
System.out.println(a[0]);
Difficulty: Hard |
Topic: Array Copy Pitfall |
Cycle: 2 (Advanced)
Why This Answer?
b = a makes b reference the SAME array as a (not a copy). Modifying b[0] also modifies a[0] because they point to the same array object.
Common Mistake
Watch Out!
Thinking = creates a copy of an array.
AP Exam Strategy
Array assignment copies the REFERENCE, not the array. Both variables point to same array.
Master This Topic
This Cycle 2 HARD question tests array copy pitfall. Review Unit 4 concepts to build mastery of data collections.
- Understanding array copy pitfall
- Tracing code execution accurately
- Avoiding common pitfalls
Ready for More Challenges?
Cycle 2 questions prepare you for the hardest AP CSA exam questions.
Study Games Practice FRQs