Amazon Interview Question for Software Engineer / Developers






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

Did Amazon mail you this code after your 2nd phone interview? This code would leak memory. Base class' destructor has to be virtual.

- Khoa April 25, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

m_derivedArray will not be deallocated because base class destructor is not virtual.

- DR April 25, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

yeah, they mailed me before the phone interview and asked the question in the interview.

Ok, i did answer the same answer but what would it be if the base class destructor is declared virtual, then the memory leak will be in the base class destructor right?

- kiran April 25, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If Base class destructor is declared virtual, then there's no memory leak. The destructor for derived class would be called first then Base class destructor. You should use whatever compiler you're familiar with and play around with this examply. It's actually a very popular C++ question.

- Khoa April 25, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

in case if base class destructor is virtual how would you free the memory associated with the pointer in the base class. I don't know c++ much would you please explain me with this

- su30mki April 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The problem is with the "inline virtual destructor" in derived class. Virtual Destructors/Constructors shouldn't be defined inline.

- veera May 10, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The code above still compiles for me. I do not understand what you mean by default constructor not present having to do with compiling error? I don't see it anywhere where it is calling a default constructor.

- bwc September 12, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

There is also a compile time error:-
The default constructor is not present. So, when Class B's constructor tries to call Class A's default constructor, it finds none.
So, either we should provide a separate default constructor for Class A or we assign a default value to the single parameter constructor.

- Jack July 02, 2007 | 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