answer of "one" was incorrect and that it really should have been "zero".
I did not make such claim! That's bullshit!
and for some obviously making such an adjustment is more difficult than it is for
others.
That's more than bullshit, that's straight-out slander! OMG! ROTFL!
Just kidding, but because you seem to take interest in me here's what
I'd answer to these questions..
1. In a CPP program what does memory leak occure?
I'm assuming that's not the original question, I think the "what"
should read "where", or the question in general tried to query HOW
memory leaks occur, in general. Apologies but I am unable to answer
nonsense question with facts so I had to do some reconstruction here.
Apologies if I am wrong. Okay, to the answer.
Usually memory leak occurs when memory is allocated with
new/new[]/malloc and matching delete/delete[]/free is missing. That's
the most typical way to conjure this beast anyway.
2. ok, the delete operator is used .. variables were freed. but still
memory leak occurs .. tell me why
Apperently not all delete operators were called where needed. It is a
common pattern to allocate memory in one place, and free it on other
place without one-to-one correspondence and clear ownership model.. in
models like this memory leaks are easy to conjure if the policy is not
followed throughout. Or maybe the destructor of object doesn't delete
memory that should be it's responsibiliy to delete.
Those are just the reasons that come into mind first, ther are more...
maybe a follow-up question if the interviewer is so inclined. Maybe a
discussion about losing ability to free up memory (such as pointer
going out of the scope, being in stack or part of object).
3. tell me at the end of the program , i want to prevent any kind of
memory leak still there.. how to do that?
At end of the program, it doesn't matter as all allocated memory is
freed automatically when the process terminates anyway.
Okay, so I stumbled on that one. Big Deal. Maybe this is a hook for
memory leak detection? I wouldn't guess the intention of the question
just say what I think about the issue. That's what I think.
4. what is the size of empty class and its object?
Enough to guarantee unique address for instances of the class. <-
Really, that is what I would answer. The expected follow up is: "And
how would you do that", I would say that's up to the compiler vendor to
decide because I wouldn't want the job anyway and would be a smartass
and just enjoy the situation a while before I take my shit and leave.
Really!
5. I want to define a class in such a way so that no further class can
be derived from it?
I haven't ever thought about that, but I guess making the default
constructor private, and then not giving the class any other
constructors? When I don't know for sure, I don't try to hide it. I
even ask my colleagues for help when I need it. You see here in Finland
we have this open thing about working places where you can go and ask
w/o shame, and no need to promose yourself all the time. A strange
cultural thing, or maybe it is just where I work.
So in short: wow, I don't know! Hope my theory turns out to be okay,
notice that I would immediately test it given the chance. Notice also
that I didn't rush out to the compiler and c++ specs to check answer
first and test it in practise.
6. In a doubly link list ,, how can u decide a head and a tail node?
The simple solution is to have "NULL" pointer at prev in the head node
and "NULL" pointer at next in the tail node.
Inserting nodes to front or back of the sequence is simpler, however,
if there is a sentinel node at each end. This can give a slight speed
bump in iteration as the value isn't constant like "NULL" pointer would
be (consumes more registers).
The mileage varies depending on what tradeoffs the implementation is
willing to do.
.... end
That's about it. Please rate my answers as possible employer, please be
fair and give me how you would rate me. I'm interested as I never been
to a job interview (the employers always seek me rather than the other
way around).