ProgrammingHardProduct-company placement · C++

Which line fails to compile?

Which line fails to compile?
int main() {
    int a[3] = {1, 2, 3}, b[3];
    b = a;                    // L1
    array<int, 3> c{1, 2, 3}, d;
    d = c;                    // L2
}
  1. A. L2 only
  2. B. L1 only
  3. C. Both
  4. D. Neither

Correct answer: B. L1 only

Built-in arrays cannot be assigned as a whole (a decays to a pointer). std::array wraps the array in a class, so it gets copy assignment, and can also be passed and returned by value.

More OOP with C++ and Java questions

Exams that ask this topic