← Quiz: Copy Constructor and Deep Copy: all 10 questions
Quiz: Copy Constructor and Deep Copy · Question 2 of 10
What does this print? (code)
What does this print?
#include <iostream>
using namespace std;
struct T {
T() {}
T(const T &) { cout << "C"; }
T &operator=(const T &) { cout << "A"; return *this; }
};
void f(T x) {}
int main() {
T a;
T b = a;
b = a;
f(a);
return 0;
}
- A.CAA
- B.CCA
- C.CAC
- D.AAC
Answer & explanation
Correct answer: CAC
T b = a constructs (C), b = a assigns (A), and passing by value constructs a copy (C).
Can you get the rest right without peeking?
Take the timed Quiz: Copy Constructor and Deep Copy quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →