一些问题 。请提供反馈 [英] some questions . please give feedback

查看:55
本文介绍了一些问题 。请提供反馈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我接受了关于C ++的采访

问的问题和我对他们的回答..


1在CPP程序中发生了什么内存泄漏?

- 我说..在构造函数中,指针变量被分配了

a内存块但是程序员忘了释放它们通过usng删除操作符在

析构函数中。


2.确定,使用了删除运算符..变量被释放。但仍然发生内存泄漏的b $ b $告诉我为什么

- 没有回答


3.告诉我最后该程序,我想防止任何类型的

内存泄漏仍然存在..怎么做?

- 没有回答


4.空类及其对象的大小是多少?

- 一个字节


5.我想在这样定义一个类一种方式,以便没有进一步的课程可以从它得到


- 没有回答


6.加倍链接列表,你如何决定头部和尾部节点?


请查看我的答案并尝试给我反馈。


谢谢,

Cric

解决方案

fr ******* @ yahoo.com 写道:


我参加了关于C ++的采访
问题问我和我的答案..

1.在CPP计划中,内存泄漏是什么?
- 我说..在构造函数中,指针变量被分配了一个内存块,但是程序员忘记了通过usng delete操作符在
析构函数中释放它们。


更一般地说,当指向分配的内存

的指针丢失时会发生内存泄漏。以多种方式 - 通过覆盖它,由于没有将b $ b存储它,当存储它的结构本身被删除时未能释放它,并且等等。

2.好的,使用删除运算符..变量被释放。但仍然发生内存泄漏..告诉我为什么
- 没有回答


这种类型的泄漏可能发生在派生类的对象是

作为指向基类的指针被删除,而基类没有虚拟的

析构函数。在这种情况下,在派生的

类中声明的成员变量不会被销毁。

3.在程序结束时告诉我,我想阻止任何类型的<内存泄漏仍然存在..怎么办?


使用编程环境提供的调试工具

,如某些基于UNIX的系统上的MallocDebug,报告任何内存

在程序终止时仍然分配的块。

4.空类及其对象的大小是多少?
- 一个字节


它的大小大于零字节。

5.我想以这样的方式定义一个类,以便不能从中派生出更多的类?
- 没有答案


声明其构造函数是私有的,并提供工厂方法来实现该类的实例。

6.在双重链接列表中,,你怎么决定头部和尾部节点?




翻转一枚硬币。实际上,我相信下一个

尾节点中的链接将为null,而之前的节点将为空。 head节点中的链接为空。


Greg


2005年10月16日23:29:47 -0700," fr ******* @ yahoo.com"

< fr ******* @ yahoo.com>写道:


我接受了关于C ++的采访
问题问题和我对他们的回答..

1。在CPP程序中发生了什么内存泄漏?
- 我说..在构造函数中,指针变量被分配了一个内存块,但程序员忘记在
析构函数中释放它们通过usng删除操作符。

2。好的,使用删除操作符..变量被释放。但仍然发生内存泄漏..告诉我为什么
- 没有答案
一些释放的数据可能包含其他动态指针,而不是
被破坏。一些内存可能是通过使用C运算符alloc或

另一种不同的方式分配的,并且从未释放或使用哪种方法

3。告诉我在程序结束时,我想防止任何类型的内存泄漏仍然存在..怎么做?
- 没有回答
你可能会重载全局运算符new和删除,这样他们就会在一些未释放的数据的某处留下

,并使用这些痕迹做一个

最终释放(但没有删除任何对象)

对于其他分配内存的方式,每个应该按照自己的方式对待它。

4。空类及其对象的大小是多少?
- 一个字节

5。我想以这样的方式定义一个类,以便不能从它派生更多的类?
- 没有答案


让所有构造函数私有
6。在双重链接列表中,您如何确定头部和尾部节点?
头节点:指向前一个的指针是0(或其他一些值意味着

开头)

尾节点:指向nect的指针是0(或其他一些值含义结束)

请查看我的回答并尝试给我反馈。

谢谢,
Cric



>> 4.空类及其对象的大小是多少?

- 一个字节



它的大小大于零字节。




继承时大小可以是零字节。


class foo

{

};


class bar:public foo // foo在这种情况下可以是0字节

{

int x;

};


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

解决方案

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


On 16 Oct 2005 23:29:47 -0700, "fr*******@yahoo.com"
<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.

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



>> 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;
};


这篇关于一些问题 。请提供反馈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆