Question 4
Back to Exercise
Given int a[3] = {1, 2, 3}, b[3];, which statement is true?
- A b = a; copies all three elements
- B b = a; makes b point to a
- C b = a; is a compile error; copy with a loop or memcpy() Correct
- D b = a; copies only a[0]
Correct Answer: Option C
An array is not a modifiable lvalue, so it cannot appear on the left of =. Use a loop or memcpy(b, a, sizeof a). (Wrapping the array in a struct does allow assignment.)
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!