Amazon Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
1
of 1 vote

sample x1=x2; //calls copy constructor
sample x1;
x1=x2 ; //calls assignment operator

- Anonymous July 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

They are the same... In the sense both of them perform a shallow copy by default. You can override the default copy constructor or overload the assignment operator for a deep copy.

- MJ July 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

So the same default behaviour implies they are same?

- LOLer July 08, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

"They are the same... In the sense"....should tell you something...apart from the implied difference i thought everyone knew that calling a copy constructor would involve creating a new object whereas an assignment operator could be between two existing objects..

- MJ July 08, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

If everyone knows, why even bother?

- LOLer July 09, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

ok smart ass...

- MJ July 09, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

a copy constructor is created by overloading the assignment operator and we can declare and define in the same expression.. whereas this is not possible through assignment operator

- lakshman July 22, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Copy Constructor is invoked when initializing an object with another (we can make the copy constructor make a deep copy).

An overloaded assignment operator is invoked when object to object assignment is done.(Again we can make sure that this assignment does a deep copy/assignment).

- Dinesh Bhirud July 30, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Anonymous' example make it clear along with MJ's explanation...

- LLOLer August 18, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Assignment operator is used for Shallow Copy by overloading assignment operator.
Copy Constructor is used for Deep Copy

- Murugan July 08, 2009 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More