注册 登录
编程论坛 新人交流区

奇怪不知道为什么?路过的能不能找出为什么

xiaot1729 发布于 2007-11-18 13:50, 891 次点击
我用了delete p;为什么以下程序运行不会出现异常?我不是已经delete p了,为什么还可以运行?
#include<iostream.h>
#include<stdio.h>
void main(){
char *p,*q;
printf("p=%d\n",p);
printf("q=%d\n",q);
p=new char;
*p='0';
q=p;
printf("p=%d\n",p);
printf("q=%d\n",q);
cout<<"*p="<<*p<<endl;
cout<<"*q="<<*q<<endl;
delete q;
printf("p=%d\n",p);
printf("q=%d\n",q);
cout<<"*p="<<*p<<endl;
cout<<"*q="<<*q<<endl;
}
8 回复
#2
xiaot17292007-11-18 14:09
怎么没人回复??
#3
thxyao2007-11-18 18:27
路过
#4
lilan2007-11-18 18:29
呀,看都看不明白
我的matilab作业都交不上呢 
帮不了你
顶一下好了
#5
orliubc2007-11-18 19:21
回复:(xiaot1729)奇怪不知道为什么?路过的能不能找...
路过,风景
#6
kaozheng2007-11-20 13:57
我觉得删除p不是用delect,它是个外部定义的变量,其实你应该把printf("p=%d\n",p);
printf("q=%d\n",q);
p=new char;
*p='0';
q=p;
printf("p=%d\n",p);
printf("q=%d\n",q);
cout<<"*p="<<*p<<endl;
cout<<"*q="<<*q<<endl;
定义为内部的,然后就不出现P的值了,
我也是新手,不知道是不是正确的。
#7
lxh9612962007-11-20 15:30
4年没碰过C 了,都不认识了
#8
sunwj012007-11-20 16:33
我也只能路过了,我看不出什么。
#9
nuciewth2007-11-20 16:38
空间是释放了,但地址还在.
1