问题描述
您好,
这是一个简单的问题,我想。
int main(){
double * g = new double;
* g = 9;
delete g;
cout<<的sizeof(克)<<" "<<的sizeof(双)<<" "<<的sizeof(* G)<<" "<< * G<<" "<< endl;
* g = 111;
cout<<的sizeof(克)<<" "<<的sizeof(双)<<" "<<的sizeof(* G)<<" "<< * G<<" "<< endl;
返回0;
}
输出:
4 8 8 9
4 8 8 111
虽然我删除了g,为什么我仍然可以使用它并且它引用
实际内存?
使用new和
删除创建和删除对象类型时也会发生同样的情况!
请不要回答您的想法,而是回答实际情况。如果
您可以指向我可以阅读的网络资源,那将是
太棒了!
谢谢提前。
问候,
jimjim
Hello,
This is a simple question for you all, I guess .
int main(){
double *g= new double;
*g = 9;
delete g;
cout<< sizeof(g)<<" "<<sizeof(double)<<" "<<sizeof(*g)<<" "<<*g<<" "<<endl;
*g = 111;
cout<< sizeof(g)<<" "<<sizeof(double)<<" "<<sizeof(*g)<<" "<<*g<<" "<<endl;
return 0;
}
The output:
4 8 8 9
4 8 8 111
Although I delete g, why is it that I can still use it and it references to
actual memory?
The same happens when creating and deleting object types with new and
delete!
Please dont answer with what you think but with what actually happens. If
you can point me to web sources I can read on this, it would have been
great!
Thank you in advance.
Regards,
jimjim
推荐答案
(comp.lang.c ++就是这样----->)
你的帖子是comp.lang.c的主题。请访问
用于发布指南和常见问题。谢谢。
-
Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我
ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。
(comp.lang.c++ is that way ----->)
Your post is off-topic for comp.lang.c. Please visit
http://www.ungerhu.com/jxh/clc.welcome.txt
http://www.eskimo.com/~scs/C-faq/top.html
http://benpfaff.org/writings/clc/off-topic.html
for posting guidelines and frequently asked questions. Thank you.
--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.
(comp.lang.c ++就是这样----->)
你的帖子是comp.lang.c的主题。请访问
用于发布指南和常见问题。谢谢。
-
Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我
ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。
(comp.lang.c++ is that way ----->)
Your post is off-topic for comp.lang.c. Please visit
http://www.ungerhu.com/jxh/clc.welcome.txt
http://www.eskimo.com/~scs/C-faq/top.html
http://benpfaff.org/writings/clc/off-topic.html
for posting guidelines and frequently asked questions. Thank you.
--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.
在那里停下来:这个问题只是因为我们的非简单
- 所有这些都在comp.lang.c中。对于他们来说也许这很简单
-在comp.lang.c ++中都是如此。当您穿过非军事区时,请仔细踩下
。
-
这篇关于使用delete来销毁原始/对象类型但不释放内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!