new运算符分配的是地址值,怎么会输出变量的值呢???
netvc 2001-08-07 03:10:02 在下面的程序中,cout<<pa[i]<<" ";怎么能够输出数值呢?它不是地址值吗??
#include <iostream.h>
#include <stdlib.h>
void fun()
{
int *p;
if (p = new int)
{
*p = 5;
cout<<*p<<endl;
delete p;
}
else
cout<<"Heap error!\n";
}
void main()
{
fun();
int *pa;
pa = new int[5];
if (!pa)
{
cout<<"Heap error!\n";
exit(1);
}
for (int i=0; i<5; i++)
pa[i] = i+1;
for (i=0; i<5; i++)
cout<<pa[i]<<" ";
cout<<endl;
delete[] pa;
}