Technical Interview Question: Is there a bug?
Is there a bug in the following C++ code snippet?
I’ll post my answer in a while once interested people post some answers. This is a pretty easy one for experts but a real good one to check OO basics of C++ candidates.
Yes there is a bug. Its a memory leak, be aware that a virtual function call from a constructor/destructor will not behave as expected. The call will not call the implementation in the derived class. You’ll not get an error message either. You’ll take notice of the bug only until the memory starts growing, god forbid this happens in production environment. You’ll end up having to call me up.
The correct way to fix such issues is to use the C++ STL classes or the equivalent language collection classes to avoid direct memory allocation. The other and probably the ideal way to fix this issue is to let the allocator be the de-allocator. So if derived is allocating then let derived do de-allocation.
This one is a brain teaser for my native programmers.
Prove via code the direction of a threads’ stack growth i.e is it upwards or downwards.
Post your answer as a comment. I’ll post mine in a while.
I had this collection of general interview questions that get’s asked during interview. I’m not sure from where I got it hence unable to link this up to the concerned website but its a good read. Full credit to the people who wrote this.
What kind of salary do you need? Are you applying for other jobs? Why should we hire you? Review these typical interview, questions and think about how you would answer them, Read the questions listed; you’ll also find some strategy suggestions with it.
Be prepared with a quote or two from co-workers. Either a specific statement or a paraphrase will work. “Jill Clark, a co-worker at Smith Company, always said I was the hardest worker she had ever known.” It is as powerful as Jill having said it at the interview herself.
A loaded question. A nasty little game that you will probably lose if you answer first. So, do not answer it. Instead, say something like, “That’s a tough question. Can you tell me the range for this position?” In most cases, the interviewer, taken off guard, will tell you. If not, say that it can depend on the details of the job. Then give a wide range.
This a trap question. Think “real hard” but fail to come up with anything that irritates you. A short statement that you seem to get along with folks is great.
Your ability to focus on projects.
Don’t get trivial or negative. Safe areas are few but can include.
You Set high standards for yourself and meet them.
Your outcomes are a success.
Your boss tells you that you are successful.
Here you have to come up with something or you strain credibility. Make it a small, well-intentioned mistake with a positive lesson learned. An example would be … working too far ahead of colleagues on a project and thus throwing coordination off.
Emphasize benefits to the organization. Things like, “determination to get the job done” and “work hard but enjoy your work” are good.
Always have some questions prepared. Questions involving areas where you will be an asset to the organization are good. “How soon will I be able to be productive?” and “What type of projects will I be able to assist on?” are examples.