C++ Programming - Constructors and Destructors - Discussion

Discussion :: Constructors and Destructors - General Questions (Q.No.10)


Copy constructor must receive its arguments by __________ .

[A]. either pass-by-value or pass-by-reference
[B]. only pass-by-value
[C]. only pass-by-reference
[D]. only pass by address

Answer: Option C


No answer description available for this question.

Abarna said: (Aug 23, 2012)  
Please tell me the difference between pass by value and pass by reference.

Susil Kumar Rout said: (Sep 17, 2012)  
We can pass arguments to functions in two ways-
1)Pass by value(Call by value)
2)Pass by reference(Call by reference)
In case of Pass by value we pass the arguments to the called function by the value only.So any change in called function will not affect the calling function.
But in case of pass by reference we pass address to the calling function.So any change in the arguments of called function will affect to the calling function.

Pradeep said: (Nov 5, 2013)  
In case of pass by reference the arguments are passed as values in calling function and received in called function as address variables, any changes done in called function reflects back to calling function.


sum(int a=10,int b=20)

sum(int &a,int &b)

Hemu Jai said: (Jan 18, 2014)  
Please tell me what is calling function, what is called function?

Rahat said: (May 9, 2014)  
void main()//calling function

func();//called function

void func()

Rahat said: (May 9, 2014)  
In the case of copy constructor, if pass by reference is not used, then to copy the passed value to the parameter object, copy constructor again called, similarly infinite number of call of copy constructor happens. But when pass by reference is used, then only reference variable simply refer to the passed object by same address, in this case copy operation does not occur.

K2U2007 said: (Oct 19, 2014)  
A constructor is the copy constructor if its first parameter is a reference to the class type and any additional parameters have default values:

class Foo {
Foo(); // default constructor
Foo(const Foo&); // copy constructor
// ...

The first parameter must be a reference type. That parameter is almost always a reference to const, although we can define the copy constructor to take a reference to non const. The copy constructor is used implicitly in several circumstances. Hence, the copy constructor usually should not be explicit.

Sravan said: (Jul 6, 2015)  
What is the difference between pass by address and pass by reference?

Yogeshwari said: (Jan 19, 2016)  
Actual meaning of the reference is that reference want return address from main function and address doesn't.

Pritam said: (Jun 11, 2019)  
The syntax of the copy constructor.

classname (const classname& object_name);

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.