Multiple choice technology programming languages

int he below code, which declaration hold for copy constructor? class C{ int x; public: C(int t);//-----> (1) C(C t); //-----> (2) C(C& t); //-----> (3) C(C t, int k);// ------> (4) };

  1. (1)

  2. (2)

  3. (3)

  4. (4)

Reveal answer Fill a bubble to check yourself
B,C Correct answer
Explanation

A copy constructor in C++ takes a reference to an object of the same class. Declaration (3) 'C(C& t);' is the correct form - it accepts a reference to a C object. Declaration (2) 'C(C t);' creates a copy constructor that takes by value, which would cause infinite recursion (copying the argument requires calling the copy constructor), but C++ treats this as a valid declaration despite being problematic. The standard form is (3), and (2) is technically a copy constructor declaration though ill-formed.