指针的一点点问题(拜托请给出详细的解决方法,如原因这些 ,谢谢了)

来源:百度知道 编辑:UC知道 时间:2024/06/28 22:44:30
#include<iostream>
using namespace std;
int Fn1();
int main()
{
int a=Fn1();
cout<<"the balue of a is:"<<a;
return 0;
}
int Fn1()
{
int *P=new int (5);
return *p;
}

你的大小写不一致,而C++是大小写敏感的,这样你导致了小写p未定义,晕。

p是指针,你只把它分配了空间而没有赋值,还有这句错了应该是:
int *p=new int [5*sizeof(int)]

int *P=new int[5];
return *P;

注意大小写