C++ Programming - Constructors and Destructors - Discussion

Discussion Forum : Constructors and Destructors - General Questions (Q.No. 10)
10.
Copy constructor must receive its arguments by __________ .
either pass-by-value or pass-by-reference
only pass-by-value
only pass-by-reference
only pass by address
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
12 comments Page 1 of 2.

Pradeep said:   1 decade ago
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.

Example:

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

sum(int &a,int &b)
(1)

Yogeshwari said:   10 years ago
Actual meaning of the reference is that reference want return address from main function and address doesn't.
(1)

Abarna said:   1 decade ago
Please tell me the difference between pass by value and pass by reference.

Susil Kumar Rout said:   1 decade ago
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.

Hemu jai said:   1 decade ago
Please tell me what is calling function, what is called function?

Rahat said:   1 decade ago
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.

Rahat said:   1 decade ago
void main()//calling function
{

func();//called function
}

void func()
{}

K2u2007 said:   1 decade ago
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 {
public:
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:   1 decade ago
What is the difference between pass by address and pass by reference?

Pritam said:   6 years ago
The syntax of the copy constructor.

classname (const classname& object_name);


Post your comments here:

Your comments will be displayed after verification.