🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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;
}
  1. A.CAA
  2. B.CCA
  3. C.CAC
  4. 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 →