Difference between a "assignment operator" and a "copy constructor"

Difference between a "assignment operator" and a "copy constructor"

many diff are there :
> Assignment operator assign the object of one object to another aftr the 1st object is fully created but in copy constructor it
assign the value of one object to another at the time of its creation .
> The copy constructor is use for initialising a new instance from an old instance, And is called when passing variables by value into functions
or as return values out of functions. but in Assignment operator is used to change an existing instance to have the same values as the rvalue, which means that the instance has to be destroyed and re-initialized if it has internal dynamic memory.
> Copy constructor  copies a existing object to a non existing object, which we are going to create. Assignment operation can happen between two existing objects.
> The copy constructor is creating a new object. But in The assignment operator has to deal with the existing data in the object.
> Copy constructor creates shallow copy but in assignment operator creates deep copy.
> The copy constructor is called at initialising the object but the assignment operator is used to assign one object to another.
> Copy constructor donot return anything. But in 
Assignment operator returns object of same type.
> The copy constructor  initializes uninitialized  memory, But in assigenment operator starts with an existing initialized objects. 
> Copy constuctor initialize the object with the another object of same class But assignment operator can be called on objects of different classes .

Date:2031-12-08 00:00:00

Post Your Answers

User Email:

User Name:

Related C Subjective Links

C Subjective interview questions and answers for experienced and fresher