标题:
一个C++程序的问题
[打印本页]
作者:
张哲上
时间:
2007-10-2 10:20
标题:
一个C++程序的问题
大家好:
有谁能帮帮我,我现在有个问题总是百思不解,望详细解答一下,谢谢了!
第一个程序:
#include<iostream>
using namespace std;
int main()
{
int *p1,*p2;
p1 = new int;
*p1 = 42;
p2 = p1;
cout << "*p1 == " << *p1 << endl;
cout << "*p2 == " << *p2 << endl;
*p2 = 53;
cout << " *p1 == " << *p1 << endl;
cout << "*p2 == " << *p2 <<endl;
delete p1;
p1 = new int;
*p1 = 88;
cout << "*p1 == " << *p1 << endl;
cout << "*p2 == " << *p2 << endl;
cout << "Hope you got the point of this example!\n";
return 0;
}
第二个程序:
#include<iostream>
using namespace std;
int main()
{
int *p1,*p2;
p1 = new int;
*p1 = 42;
p2 = p1;
cout << "*p1 == " << *p1 << endl;
cout << "*p2 == " << *p2 << endl;
*p2 = 53;
cout << " *p1 == " << *p1 << endl;
cout << "*p2 == " << *p2 <<endl;
p1 = new int;
*p1 = 88;
cout << "*p1 == " << *p1 << endl;
cout << "*p2 == " << *p2 << endl;
cout << "Hope you got the point of this example!\n";
return 0;
}
为什么第一个程序比第二个程序多了一个 delete p1 后结果会不同呢?
作者:
leelee
时间:
2007-10-2 16:40
楼主的vc6有没有打过补丁
作者:
qq2008444
时间:
2007-10-2 17:08
呵呵
没办法帮忙
道歉先
欢迎光临 微点交流论坛 (http://bbs.micropoint.com.cn/)
bbs.micropoint.com.cn