|
INTERVIEW QUESTIONS
C++
OPERATORS IN C++
DETAILS
Question: Define copy constructor? What is the use of copy constructor?
Answer: A copy constructor is used to initialize a newly declared variable from an existing variableA variable is declared which is initialized from another object,A value parameter is initialized from its corresponding argument.f(p); // copy constructor initializes formal value parameter. An object is returned by a function.C++ calls a copy constructor to make a copy of an object in each of the above cases. If there is no copy constructor defined for the class, C++ uses the default copy constructor which copies each field, ie, makes a shallow copy.
|
|
|
Category |
Operators in C++ Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 7424 users |
Added on |
7/19/2011 |
Views |
71484 |
Rate it! |
|
|
Question:
Define copy constructor? What is the use of copy constructor?
Answer:
A copy constructor is used to initialize a newly declared variable from an existing variableA variable is declared which is initialized from another object,A value parameter is initialized from its corresponding argument.f(p); // copy constructor initializes formal value parameter. An object is returned by a function.C++ calls a copy constructor to make a copy of an object in each of the above cases. If there is no copy constructor defined for the class, C++ uses the default copy constructor which copies each field, ie, makes a shallow copy. Source: CoolInterview.com
The copy constuctor is used to initialize an object by copying the state from another object of the same class. It takes a reference to an object of the same class as itself as an argument.
A copy constructor is invoked when an object is passed by value, returned by value or explicitly copied.
Source: CoolInterview.com
Answered by: Monalisha Nayak | Date: 6/15/2009
| Contact Monalisha Nayak
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
In C++, what is a constructor,destructor?
|
View Answer
|
|
Can you declare the override method static while the original method is non-static?
|
View Answer
|
|
How can you overload a method?
|
View Answer
|
|
What is a scope resolution operator?
|
View Answer
|
|
Difference between realloc() and free()?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All Operators in C++ Interview Questions & Answers - Exam Mode /
Learning Mode
|