Multiple choice technology programming languages

If X is the name of the class, what is the correct way to declare copy constructor of X?

  1. X(X arg)

  2. X(X* arg)

  3. X(const X* arg)

  4. X(const X& arg)

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

A copy constructor in C++ must take a constant reference to the same class type. It uses X(const X& arg) to avoid unnecessary copying and allow passing both lvalues and rvalues. The other options use pointer syntax which would create different constructor signatures and not serve as copy constructors.