473,837 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

some questions . please give feedback

Hi,
I attanded an interview on C++
Question asked were and my answers to them..

1. In a CPP program what does memory leak occure?
-- i said.. In a constructor , the pointer variables were assigned
a memory block but the programmer forgets to free them in the
destructor by usng delete operator.

2. ok, the delete operator is used .. variables were freed. but still
memory leak occurs .. tell me why
-- no answer

3. tell me at the end of the program , i want to prevent any kind of
memory leak still there.. how to do that?
-- no answer

4. what is the size of empty class and its object?
-- one byte

5. I want to define a class in such a way so that no further class can
be derived from it?
-- no answer

6. In a doubly link list ,, how can u decide a head and a tail node?

Please review my answer and try to give me feedback.

thanks,
Cric

Oct 17 '05 #1
18 2507
fr*******@yahoo .com wrote:
Hi,
I attanded an interview on C++
Question asked were and my answers to them..

1. In a CPP program what does memory leak occure?
-- i said.. In a constructor , the pointer variables were assigned
a memory block but the programmer forgets to free them in the
destructor by usng delete operator.
More generally, a memory leak occurs when a pointer to allocated memory
is "lost" in any number of ways - by overwriting it, by a failure to
store it, by a failure to free it when the structure which stored it
was itself deleted, and so forth.
2. ok, the delete operator is used .. variables were freed. but still
memory leak occurs .. tell me why
-- no answer
This type of leak can happen when an object of a derived class is
deleted as a pointer to a base class, and the base class has no virtual
destructor. In this case the member variables declared in the derived
class are not destroyed.
3. tell me at the end of the program , i want to prevent any kind of
memory leak still there.. how to do that?
Use the debugging facilities offered by the programming environment
such as MallocDebug on some UNIX based systems, to report any memory
blocks still allocated at program termination.

4. what is the size of empty class and its object?
-- one byte
Its size is greater than zero bytes.
5. I want to define a class in such a way so that no further class can
be derived from it?
-- no answer
Declare its constructor private and provide a factory method to
instantiate instances of the class.
6. In a doubly link list ,, how can u decide a head and a tail node?


Flip a coin. Actually, I believe the "next" link would be null in the
tail node, and the "previous" link would be null in the head node.

Greg

Oct 17 '05 #2
On 16 Oct 2005 23:29:47 -0700, "fr*******@yaho o.com"
<fr*******@yaho o.com> wrote:
Hi,
I attanded an interview on C++
Question asked were and my answers to them..

1. In a CPP program what does memory leak occure?
-- i said.. In a constructor , the pointer variables were assigned
a memory block but the programmer forgets to free them in the
destructor by usng delete operator.

2. ok, the delete operator is used .. variables were freed. but still
memory leak occurs .. tell me why
-- no answer Some of the data freed may contain other dynamic pointers that are not
destroyed. Some memory might be allocated by using C operator alloc or
another dofferent means, and never freed or whichever methos is used

3. tell me at the end of the program , i want to prevent any kind of
memory leak still there.. how to do that?
-- no answer You may overload global operator new and delete, such that they leave
somewhere a trace of data not freed, and use this traces to do a
final freeing (but with no object deleting)
For the other ways of allocating memory, each should be treated its
own way

4. what is the size of empty class and its object?
-- one byte

5. I want to define a class in such a way so that no further class can
be derived from it?
-- no answer
Make all constructors private
6. In a doubly link list ,, how can u decide a head and a tail node? head node: pointer to previous is 0 (or some other value meaning
beginning)
tail node: pointer to nect is 0 (or some other value meaning end)

Please review my answer and try to give me feedback.

thanks,
Cric

Oct 17 '05 #3
>> 4. what is the size of empty class and its object?
-- one byte


Its size is greater than zero bytes.


The size can be zero bytes when doing inheritance.

class foo
{
};

class bar : public foo // foo can be 0 bytes in this case
{
int x;
};

Oct 17 '05 #4
No, my result is foo size is 1
My environment: Visual Studio .Net 2003

Oct 17 '05 #5
persenaama wrote:
4. what is the size of empty class and its object?
-- one byte


Its size is greater than zero bytes.


The size can be zero bytes when doing inheritance.

class foo
{
};

class bar : public foo // foo can be 0 bytes in this case
{
int x;
};


The incremental increase in the size of class by adding a member can be
zero (known as "the empty base class optimization") but the size of a
class itself is always non-zero.

Besides, it's easy to tell the motivation behind this question. "Zero"
would be the obvious, naive answer which is exactly why any answer
mentioning a zero-sized object would lose points. And the applicant
will not gain points by complicating the answer with extraneous
information, which even if correct, makes the answer harder to
understand and for the interviewer to decide whether it is completely
correct.

Greg

Oct 17 '05 #6
* Greg:
persenaama wrote:
> 4. what is the size of empty class and its object?
> -- one byte

Its size is greater than zero bytes.


The size can be zero bytes when doing inheritance.

class foo
{
};

class bar : public foo // foo can be 0 bytes in this case
{
int x;
};


The incremental increase in the size of class by adding a member can be
zero (known as "the empty base class optimization") but the size of a
class itself is always non-zero.

Besides, it's easy to tell the motivation behind this question. "Zero"
would be the obvious, naive answer which is exactly why any answer
mentioning a zero-sized object would lose points. And the applicant
will not gain points by complicating the answer with extraneous
information, which even if correct, makes the answer harder to
understand and for the interviewer to decide whether it is completely
correct.


Well, with reasonable parsing of the text persenaama is correct, and you're
not. ;-)

The newser will not gain points by complicating the answer with extranous
information and managerial gobbledygook which, even if incorrect, gives the
posting an appearance of competence.

Nor will the newser gain points by attempts at weaseling, but only by
admitting his error.

persenaama referred as I read it to the size of an object, not of a class, and
the Holy Standard mentions specifically in note 70 that the actual size of a
base class subobject can be less than the sizeof of the subobject's class.

Mentioning a zero-sized base class sub-object, as persenaama did, should
therefore of course gain points, not lose them as you write.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oct 17 '05 #7
Alf P. Steinbach wrote:
* Greg:
persenaama wrote:
>> 4. what is the size of empty class and its object?
>> -- one byte
>
> Its size is greater than zero bytes.

The size can be zero bytes when doing inheritance.

class foo
{
};

class bar : public foo // foo can be 0 bytes in this case
{
int x;
};


The incremental increase in the size of class by adding a member can be
zero (known as "the empty base class optimization") but the size of a
class itself is always non-zero.

Besides, it's easy to tell the motivation behind this question. "Zero"
would be the obvious, naive answer which is exactly why any answer
mentioning a zero-sized object would lose points. And the applicant
will not gain points by complicating the answer with extraneous
information, which even if correct, makes the answer harder to
understand and for the interviewer to decide whether it is completely
correct.


Well, with reasonable parsing of the text persenaama is correct, and you're
not. ;-)

The newser will not gain points by complicating the answer with extranous
information and managerial gobbledygook which, even if incorrect, gives the
posting an appearance of competence.

Nor will the newser gain points by attempts at weaseling, but only by
admitting his error.

persenaama referred as I read it to the size of an object, not of a class, and
the Holy Standard mentions specifically in note 70 that the actual size of a
base class subobject can be less than the sizeof of the subobject's class.

Mentioning a zero-sized base class sub-object, as persenaama did, should
therefore of course gain points, not lose them as you write.


The original question, albeit somewhat garbled, asked for an absolute
answer. A subobject base may be smaller than the derived class, but it
doesn't have to be. And in real life even that much is uncertain since
it requires a compiler that supports this optimization in the first
place. Therefore an answer of "zero" comes with a lot qualifications,
and still doesn't provide the clearcut answer the question sought.
Wouldn't a more nuanced answer better educate the questioner? No doubt,
but the candidate has to first answer the question asked. The candidate
is not entitled to answer a different question that she would have
preferred or one that would better shown off her knowledge. And since
the question didn't mention empty subobjects or derived classes - it
mentioned only an empty class - the best thing to do - if the job is of
any interest at all - is to give the absolute answer the questioner
wants and save the lecture for another day.

Sure, veering off in one's own direction spouting reams of C++ minutiae
may dazzle the interviewer, or it may irritate the interviewer to no
end if every answer to a question asked goes on for five minutes longer
than it needs to. Imagine how well such a habit would wear on potential
coworkers. Especially, if when the answer finally winds down, the
questioner is no more sure of the answer having asked the question.

Certainly breadth and depth of knowledge have value. But unless that
knowlege can prove useful, the likelihood of being paid just because
one has the knowledge is rather slim.

Greg

Oct 17 '05 #8
* Greg:
[snipped rambling]

And since the question didn't mention empty subobjects or derived classes - it
mentioned only an empty class - the best thing to do - if the job is of
any interest at all - is to give the absolute answer the questioner
wants and save the lecture for another day.


I think you should have saved those lectures you've given here... Why not
just admit you were wrong instead of huffing & puffing? Anybody can make a
mistake.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oct 17 '05 #9
Alf P. Steinbach wrote:
* Greg:
[snipped rambling]

And since the question didn't mention empty subobjects or derived classes - it
mentioned only an empty class - the best thing to do - if the job is of
any interest at all - is to give the absolute answer the questioner
wants and save the lecture for another day.


I think you should have saved those lectures you've given here... Why not
just admit you were wrong instead of huffing & puffing? Anybody can make a
mistake.


I certainly make my share of mistakes. You need only look in my source
code to find some. But no one has made a mistake here. Persenaama's
answer does not lose points because it is incorrect. It loses points
because it is the wrong answer to give in response to that interview
question. It doesn't address the question directly, it muddies the
waters and the interviewer may not even know as much. Granted, it may
be unjust to lose points for an otherwise factually correct answer, but
this thread after all is supposed to be helping the original poster
learn how to answer C++ interview questions effectively. And we are
doing a disservice to the original poster if we are claiming that his
answer of "one" was incorrect and that it really should have been
"zero". That claim is simply misleading.

In a C++ interview, the candidate has to do more than simply be
correct. The candidate has to answer correctly the questions asked. On
USENET we can pick and choose which C++ questions to answer, a
candidate being interviewed does not have that luxury - and for some
obviously making such an adjustment is more difficult than it is for
others.

Greg

Oct 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2614
by: Az Tech | last post by:
Hi people, (Sorry for the somewhat long post). I request some of the people on this group who have good experience using object-orientation in the field, to please give some good ideas for topics to include in a course on object-orientation that I'm going to conduct. (I will later summarize all the replies and discussion, for the
12
2340
by: Vibhajha | last post by:
Hi friends, My sister is in great problem , she has this exam of C++ and she is stuck up with some questions, if friends like this group provides some help to her, she will be very grateful. These are some questions:- 7. design and implement a class binsearch for a binary search tree.it includes search,remove and add options.make suitable assumption. 8.explai how pointers to functions can be declared in c++.under what conditions can...
14
3125
by: alwayshouston | last post by:
Hi All! I am working on this very small database and I am confused in the designing a simple form. I only have three tables in the database. First Table: tblExpense Columns: ExpenseID ; ExpenseType Data: 1 ; FOOD 2 ; AIRLINE 3 ; FARE
2
2310
by: Brian Basquille | last post by:
Hello all. Air Hockey game is due up in just over a month. And i've about 2 and a half weeks to work on it. So, i need some feedback and advice. http://homepage.eircom.net/~basquilletj/AirHockey.rar Please download it and give it a quick spin. Not completely working yet in terms of:
7
2361
by: changs | last post by:
Hi, all I have a asm code, I suspect it sort of socket programming. Can anyone here give some instructions on how to determine the function or give the psudo-code in C? Thanks in advance! Tony
11
2461
by: shapper | last post by:
Hello, I am creating a centered web site with various div's inside the main (pBase) div. Somehow, I am getting a gap on the top of my browser window both in IE and Firefox. I tried everything I could think of. Here is my entire HTML code:
30
2304
by: GeorgeRXZ | last post by:
Hi Friends, I have some questions related to C Language. 1What is the difference between the standard C language and Non standard C language ? 2which is better C Lanugage, C under Linux/ Unix or C under windows/ DOS ?
2
2937
by: Stewart Berman | last post by:
I have an application that populates a DataGridView control with an XML. file. 1. How do I set up the process so the user initally sees just the headers -- no records. I have the DataGridView properties set to allow the user to edit data but not add or delete (which will be down in the program). However when I execute the ReadXML method one emtpy row is shown. The starter XML contains: <?xml version="1.0" encoding="utf-8"?>...
0
9682
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10881
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10275
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9406
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7004
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5670
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5850
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4475
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4043
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.